Chapter 3: Functions
Definition & Notation
A function is a relation between two sets, where each element of the first set (called the domain) is assigned to exactly one element of the second set (called the codomain). As illustrated below, a function can be thought of as an input/output device : for any given input, the output is uniquely determined.

We now provide a more formal definition of a function and introduce several related concepts.

A function is a rule that assigns to each input exactly one output . This relationship is often written as:
In particular:
- The set is called the domain of the function. It contains all possible valid inputs.
- The set is called the codomain. It is the set into which all outputs are mapped.
- The range (also called the image) of the function is the set of actual outputs the function produces based on its domain. It is a subset of the codomain:
When we use to denote the input and to denote the output associated with , is also referred to as the independent variable and as the dependent variable, because its value "depends on ".
A function always has a domain, which is the set of all inputs for which the function is defined. If no specific domain is stated for a function given by an equation, the default is typically the set of all real numbers that yield valid (usually real) outputs.
Functions are powerful tools for describing relationships between two quantities. Many real-world scenarios can be modeled using functions, where one variable depends on another. In this context, it is also important to understand a function’s domain, codomain, and range, as these concepts help clarify what kinds of inputs are valid, what types of outputs are expected, and what outputs actually occur.
The area of a square depends on the length of its side. If the side length is , the area is given by
- Domain: , because side lengths cannot be negative.
- Codomain: , since the function produces real-number outputs (areas measured in real units).
- Range: , because squaring any non-negative number gives a non-negative result. The smallest value occurs at , where , and as increases, grows without bound.
The temperature at a given time of day can be expressed as a function of time. Suppose the temperature (in °C) follows the rule
- Domain: , because the model describes temperature over a single day (in hours).
- Codomain: , since temperature values are real numbers.
- Range: , since the sine term varies between and . This means varies between and , and adding shifts the range to .
If a car travels at a constant speed of 60 km/h, the distance traveled after hours is given by
- Domain: , because time cannot be negative.
- Codomain: , since distances are expressed as real numbers.
- Range: , because multiplying a non-negative by 60 produces a non-negative result. The distance is at the start, and increases without bound as time increases.
The codomain defines the set of values a function is declared to produce, while the range consists of the values that actually occur.
In many cases, the codomain is chosen to be the set of real numbers, , even when the outputs are only non-negative (as in Example 1). This convention keeps real-valued functions compatible with one another, i.e., it allows us to compare, combine, and apply the same rules (for example, addition, composition, or differentiation) without worrying about mismatched output sets.
In general, the codomain specifies the structure of the output space: it tells us what kind of values a function is expected to produce, while the range shows which of those values actually occur.
Representation Methods
Functions can be represented in several different ways, each offering different insights into the relationship they describe. Depending on the context, one representation may be more useful or informative than another.
To illustrate these representations, we will use a simplified example based on (synthetically generated) agriculture data. Let denote the crop yield (in t/ha) as a function of fertilizer amount (in kg/ha). That is, we define:
This example models a common real-world scenario where one quantity (fertilizer) depends on another (crop yield).
Tables
A table is one of the most straightforward ways to represent a function. This form is especially useful when working with data collected through observation or measurement. Essentially, a table just lists specific input values and their corresponding output values.
| Fertilizer () | Crop Yield () |
|---|---|
| 0 | 3.4942 |
| 1 | 3.5038 |
| 2 | 3.5133 |
| 3 | 3.5228 |
| 4 | 3.5322 |
| 197 | 4.1589 |
| 198 | 4.1559 |
| 199 | 4.1530 |
| 200 | 4.1500 |
| 201 | 4.1469 |
| 396 | 2.3319 |
| 397 | 2.3163 |
| 398 | 2.3008 |
| 399 | 2.2851 |
| 400 | 2.2694 |
In this table, each row shows a specific input value and the corresponding output value . Tables are useful for answering discrete queries, such as: "What is the crop yield if given 200 kg/ha fertilizer?".
They can also help identify general trends in the data, which leads us to the following definitions.
We say that a function is increasing on an interval if for all it holds that
The function is said to be strictly increasing (note the inequality) when
We say that a function is decreasing on an interval if for all it holds that
The function is said to be strictly decreasing (note the inequality) when
By applying these definitions and inspecting the table, we can observe that the crop yield increases as the fertilizer amount increases - up to a certain point - and then decreases. However, beyond this general behavior, it is difficult to tell much more. The table alone does not reveal whether the relationship is simply linear, or follows a more complex curve. In particular, it does not clearly convey the rate at which the crop yield increases or whether this rate changes over the domain. For such insights, a graphical or algebraic representation is usually more informative.
Graphs
A visual picture of a function can be provided in the form of a graph. The graph of a function is the set of points plotted in a coordinate plane, where for all in the domain of . Plotting data points from a table helps reveal the overall shape and behavior of the function, which may not be immediately apparent from a list of values alone.

From this graph, we can observe that the function increases with fertilizer (), to a point, but not linearly. The curve appears to flatten and then decrease more sharply, suggesting that the relationship between fertilizer () and yield () is non-linear, possibly polynomial.
Algebraic Formulas
Often, we want more than just individual data points, we want a general rule that allows us to compute the output for any valid input. An algebraic formula provides a compact, symbolic way to describe the relationship between inputs and outputs.
The table and graphs shown above of the crop yield have actually been generated based on the quadratic polynomial:
This expression is not arbitrary, it was obtained from observed data using a method that fits a mathematical function to the measurements. In this case, the polynomial gives an approximation of the relationship between fertilizer amount and crop yield, smoothing out random variations while preserving the overall pattern seen in the data.
Having an algebraic representation allows us to carry out several useful analyses:
- Interpolation: Estimate values between known data points.
- Extrapolation: Predict behavior beyond the observed range, for instance, for very small or large fertilizer amounts ().
- Equation solving: Find input values corresponding to specific outputs, for example solving to determine the corresponding fertilizer amount that yields 4.5 t/ha.
More broadly, models based on algebraic formulas let us describe and explore real-world phenomena: how quantities change together, where growth slows or reverses, and how one variable influences another. Such models form the foundation of mathematical analysis, offering insight into underlying behavior.
To describe these relationships effectively, we must choose a suitable type of function and fit it to the data. In this example, the coefficients of the polynomial were determined using least squares regression, a method that finds the curve that best matches the observed data. Recognizing different classes of functions, such as linear, quadratic, cubic, or exponential, helps us select appropriate models and interpret the types of behavior they represent.
Basic Classes of Functions
Functions can be grouped into different classes based on their algebraic form. Each class has its own properties, domain and range, and characteristic graph shape. In this section, we focus on common basic function classes and describe their general forms (graphical) behavior.
Before exploring specific types, it is useful to note two important features that appear frequently in graphs of functions:
| Feature | Definition | Why It Matters |
|---|---|---|
| Intercepts | Points where the graph crosses the coordinate axes. -intercepts occur when , and the -intercept occurs when . | Represent starting values, equilibrium states, or solutions to problems. |
| Turning Points | Points where the graph changes direction from increasing to decreasing, or vice versa. | Indicate local maxima or minima; used to identify peaks, troughs, or optimal conditions. |
| Asymptotes | Lines that the graph approaches but does not cross (or only crosses at infinity): horizontal, vertical, or oblique. | Describe long-term trends or limits in growth/behavior; mark boundaries. |
Polynomial Functions
Polynomial functions are smooth, continuous curves with no sharp corners or breaks. Their general behavior depends on the degree and the leading coefficient.

Polynomials belong to a broad class of functions that can be written in the general form:
where:
- is a non-negative integer (the degree of the polynomial)
- are real constants
- if
Key characteristics:
- Graph: smooth, continuous curve.
- Intercepts: Up to real -intercepts; always one -intercept at .
- Domain: All real numbers ()
- Range: Depends on the degree and coefficients.
Polynomials are commonly classified based on two characteristics:
- The number of terms
- The degree of the expression
The following tables summarize these classifications with corresponding examples.
| Number of Terms | Name | Example |
|---|---|---|
| Monomial | ||
| Binomial | ||
| Trinomial | ||
| Polynomial |
| Degree | Name | Example |
|---|---|---|
| Constant | ||
| Linear | ||
| Quadratic | ||
| Cubic | ||
| Quartic | ||
| Quintic | ||
| th-degree polynomial |
Linear Functions
A linear function is a polynomial of degree and its graph is a straight line.

A linear function can be written in the general (slope-intercept) form:
where and are constants. If , it is a polynomial of degree ; if , it simplifies to , which is a constant function (a polynomial of degree 0).
Key characteristics:
- Graph: A straight line with slope .
- If the function is increasing
- If the function is decreasing
- Intercepts:
- -intercept at point
- -intercept at point
- Domain: All real numbers ()
- Range: All real numbers ()
Determine which of the following functions are linear functions:
Answer: is linear (degree 1), while is a constant function (degree 0), and is quadratic (degree 2).
One of the defining characteristics of a line is its slope. The slope describes how a line rises or falls as we move along the -axis, i.e., in other words, it represents the rate of change in for each unit change in .
The slope measures both the steepness and the direction of a line:
- If the slope is positive, the line points upward when moving from left to right
- If the slope is negative, the line points downward when moving from left to right
- If the slope is zero, the line is horizontal
To determine the slope numerically, we compare how much changes relative to . This comparison gives us the ratio of the change in to the change in , leading to the more formal definition below.
Consider a line passing through points and . Let and denote the changes in and , respectively. The slope of the line is:
Now, let us explore how this definition relates to the formula of a linear function. Consider the function:
We already know that the graph of a linear function is a straight line. To find its slope, we can apply the definition above using any two points, i.e., and , on the line. In particular, let us evaluate the function at two convenient points:
- When , we have . This gives us the point:
- When , we have . This gives us the point:
Therefore, substituting the points into the formula for the slope, the slope of this line is:
This shows that the coefficient in the function represents the slope of the line. Hence, every linear function of the form describes a line with slope and -intercept .
This relationship will be revisited in Chapter 8, where the concept of slope forms the basis for defining differentiation.
Quadratic Functions
A quadratic function is a polynomial of degree ; its graph is a parabola.

A quadratic function can be written in the general form:
where .
Key characteristics:
- Graph: A parabola.
- If the parabola opens upward
- If the parabola opens downward
- Intercepts: Up to two -intercepts, and exactly one -intercept
- Turning Point: The peak of the graph.
- If it is the lowest point
- If it is the highest point
- Domain: All real numbers ()
- Range:
- If it is
- If it is
Determine which of the following functions are quadratic functions:
Answer: and are quadratic. is cubic.
Exponential Functions
Exponential functions have a constant base raised to a variable exponent.

An exponential function can be written in the general form:
where , , and .
Key characteristics:
- Graph:
- If the graph is increasing (growth)
- If the graph is decreasing (decay)
- Asymptote: Horizontal at .
- Domain: All real numbers ()
- Range: if
Determine which of the following functions are exponential functions:
Answer: and are exponential. Here is a power function (a special case of a polynomial).
Logarithmic Function
Logarithmic functions are the inverses of exponential functions.

A logarithmic function can be written in the general form:
where , , and .
Key characteristics:
- Graph:
- Passes through if
- Slow, unbounded growth for large
- Asymptote: Vertical at .
- Domain:
- Range: All real numbers ()
Determine which of the following functions are logarithmic functions:
Answer: and are logarithmic. is exponential.
Piecewise-Defined Functions
Not all functions can be described by a single formula. In some cases, different rules apply to different parts of the domain. Such functions are called piecewise-defined functions.
A piecewise-defined function is a function whose rule is given by multiple expressions, each applying to a specific interval (or subset) of the domain. Formally, it can be written as:
where:
- Each defines the function on a subset of the domain
- The subsets are non-overlapping and form the entire domain of
- Each input belongs to exactly one of the subsets , ensuring that the function assigns one unique output for every input
Key characteristics:
- Graph: May be continuous or discontinuous at the boundary points between pieces
- Domain: The union of all subsets
- Range: The union of the output values of all pieces

Consider the function defined by
To evaluate a piecewise function, first determine which part of the domain the input belongs to, and then apply the corresponding rule. For instance:
- For , since , use function :
- For , since , use function :

The absolute value function, denoted by , can be expressed as a piecewise-defined function:
Here, positive inputs are unchanged, while negative inputs are reflected across the -axis, ensuring that is always non-negative.

The Rectified Linear Unit (ReLU) is a commonly used activation function in neural networks. It can be expressed as a piecewise-defined function:
The ReLU function outputs the input value itself when it is positive, and zero otherwise. This simple non-linear behavior introduces nonlinearity into neural networks, which is an essential property that allows them to learn complex patterns and relationships in data.
Injective, Surjective, and Bijective Functions
Functions can also be classified based on how they relate elements of their domain to elements of their codomain. While algebraic form determines a function’s shape or formula, mapping properties determine whether the function is one-to-one, onto, or both.
A function is injective (or one-to-one) if it never assigns the same output value to two different inputs. In other words, each output in comes from at most one input in .
More formally, in predicate logic, we can write:
Or in plain words: If two inputs of a function give the same output, then those inputs must be equal.

Let be defined by:
This function is injective because different -values always produce different -values. However, is not injective on since .
A function is surjective (or onto) if every element of the codomain appears as an output of the function. That means the function covers all of , i.e., its range is equal to its codomain.
More formally, in predicate logic, we can write:
Or in plain words: For every possible output value in the codomain, there exists at least one input value in the domain that produces it.

Let be defined by:
For any , there exists , so is surjective. However, from is not surjective because negative -values are never reached.
A function is bijective if it is both injective and surjective. This means that each element of is mapped to a unique element of (injectivity), and every element of is the image of some element of (surjectivity).
More formally, we can write:
Or in plain words: A bijective function establishes a one-to-one correspondence between the sets and , so that nothing is repeated and nothing is left out.

Let be defined by:
The function is bijective because each input produces a unique output (injective) and every real number occurs exactly once as an output (surjective).
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.
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.
Suppose and are functions defined on the same domain. The following operations define new functions as shown below:
| Operation | Notation | Definition |
|---|---|---|
| Sum | ||
| Difference | ||
| Product | ||
| Quotient |
Ultimately, these operations let us construct more complex relationships from simpler ones.
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 simplifies to a linear one.
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. Now, explore a different kind of combination, i.e., 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 an entire chain of dependencies as a single mathematical expression.
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 would first compute , the average temperature on day 10, and then use that value in function , i.e., gives the electricity required to cool the house on the 10th day of the year.
In this case, the function describing temperature is said to be composed with the function describing electricity usage.
The relationship illustrated above can be generalized by defining a new function that represents applying one function after another. For this to be well-defined, the range of the inner function must lie within the domain of the outer function.
This brings us to the formal definition of the composition of functions.

Let and be functions, where the codomain of (the set of its possible outputs) is contained in the domain of . The composition of and , denoted , is the function
defined by
-
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 is not commutative:
In general it is the case that
since
for most functions and . In other words, the order matters because the output of one function becomes the input of the other, and reversing that order usually produces a different intermediate value.
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 8, 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.
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
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