Unit 1 Lesson 1

What is a function?

A function assigns to each element of one set exactly one element of another. We formalise this idea, name its parts — domain, codomain, image — and state when two functions are equal.

Learning Objectives

  • State the definition of a function \(f \colon A \to B\).
  • Identify the domain, codomain, and image of a given function.
  • Distinguish a function from an arbitrary rule that fails the uniqueness or existence condition.
  • Determine when two functions are equal.
  • Recognise a sequence as a function \(\mathbb{N} \to \mathbb{R}\).

Motivation

In the Sequences course we worked with functions from \(\mathbb{N}\) to \(\mathbb{R}\): each index \(n\) determined exactly one real number \(a_n\). A sequence was a particular kind of assignment — from natural numbers to reals.

Now we step back and ask the general question: what does it mean to assign to each element of one set exactly one element of another? The answer is the concept of function, one of the most fundamental objects in all of mathematics.

Function

Let \(A\) and \(B\) be two non-empty sets. A function from \(A\) to \(B\) is a rule that assigns to each element \(a \in A\) exactly one element \(b \in B\).

We write \(f \colon A \to B\) and, for a particular element \(a \in A\), we write \(f(a)\) for the element of \(B\) that the rule assigns to \(a\). We call \(f(a)\) the image of \(a\) under \(f\), or the value of \(f\) at \(a\).

Two conditions are packed into the phrase "each element … exactly one":

  1. Existence. Every element of \(A\) must have an image. There is no element "left unassigned."

  2. Uniqueness. No element of \(A\) is assigned two different images. The rule produces one answer, not several.

If a proposed rule violates either condition, it is not a function.

Functions and non-functions

A function. Let \(A = \{1, 2, 3\}\) and \(B = \{a, b, c\}\). The rule

\[1 \mapsto b, \quad 2 \mapsto a, \quad 3 \mapsto b\]

is a function from \(A\) to \(B\): every element of \(A\) is assigned exactly one element of \(B\). Notice that two elements of \(A\) may share the same image (both \(1\) and \(3\) map to \(b\)), and that \(c \in B\) is nobody's image. Neither fact violates the definition.

Existence fails. The rule \(1 \mapsto a,\; 3 \mapsto c\) on the same sets is not a function: the element \(2 \in A\) has no image (existence fails).

Both conditions fail. Consider \(A = \mathbb{R}\) and \(B = \mathbb{R}\), with the rule "assign to each \(x\) a number \(y\) such that \(y^2 = x\)." For \(x = 4\), both \(y = 2\) and \(y = -2\) satisfy \(y^2 = 4\), so the rule assigns two values (uniqueness fails). And for \(x = -1\) there is no real \(y\) with \(y^2 = -1\) (existence also fails). This rule is not a function from \(\mathbb{R}\) to \(\mathbb{R}\).

Domain, codomain, image

For a function \(f \colon A \to B\):

  • The set \(A\) is called the domain of \(f\). Every element of the domain has an image.

  • The set \(B\) is called the codomain of \(f\). It is the set in which images live, but not every element of \(B\) need actually appear as an image.

  • The image (or range) of \(f\) is the set \[\mathrm{Im}(f) = \{f(a) \mid a \in A\} \subseteq B.\] It is the subset of \(B\) that is actually "hit" by \(f\).

Domain, codomain, image — concrete cases

A finite function. Let \(f \colon \{1, 2, 3\} \to \{a, b, c\}\) with \(1 \mapsto b,\; 2 \mapsto a,\; 3 \mapsto b\). Then:

  • Domain: \(\{1, 2, 3\}\).

  • Codomain: \(\{a, b, c\}\).

  • Image: \(\{a, b\}\). The element \(c\) is in the codomain but not in the image.

The squaring function. Let \(f \colon \mathbb{R} \to \mathbb{R}\), \(f(x) = x^2\). The domain is \(\mathbb{R}\), the codomain is \(\mathbb{R}\), but the image is \([0, +\infty)\) — no negative number is a square.

Notation conventions

You will meet two slightly different notations. The first names the function and its domain and codomain:

\[f \colon A \to B\]

The second also describes the rule element-by-element:

\[f \colon A \to B, \quad x \mapsto f(x)\]

The arrow \(\to\) connects two sets; the arrow \(\mapsto\) connects an element to its image. They are not interchangeable.

Sequences as functions

A sequence \((a_n)_{n \geq 0}\) is a function \(a \colon \mathbb{N} \to \mathbb{R}\), where \(a(n) = a_n\). The domain is \(\mathbb{N}\) (or a subset such as \(\{0, 1, 2, \ldots\}\) or \(\{1, 2, 3, \ldots\}\)), the codomain is \(\mathbb{R}\), and the image is the set of values the sequence actually takes.

Everything we proved about sequences — monotonicity, boundedness, and so on — was really a statement about a particular class of functions. The general theory of functions that we build in this course subsumes those earlier results.

Equality of functions

Two functions \(f \colon A \to B\) and \(g \colon C \to D\) are equal if and only if all three of the following hold:

  1. They have the same domain: \(A = C\).

  2. They have the same codomain: \(B = D\).

  3. They agree on every input: \(f(x) = g(x)\) for all \(x \in A\).

Changing the domain, the codomain, or the rule — even at a single point — produces a different function.

Equal or not?

Different domains. Let \(f \colon \mathbb{R} \to \mathbb{R},\; f(x) = x^2\) and \(g \colon [0, +\infty) \to \mathbb{R},\; g(x) = x^2\). Although the rule is the same formula, the domains differ (\(\mathbb{R}\) vs. \([0, +\infty)\)), so \(f \neq g\).

Different codomains. Let \(f \colon \mathbb{R} \to \mathbb{R},\; f(x) = x^2\) and \(h \colon \mathbb{R} \to [0, +\infty),\; h(x) = x^2\). Same domain, same rule, but different codomains (\(\mathbb{R}\) vs. \([0, +\infty)\)), so \(f \neq h\).

This may feel pedantic, but it matters: the two functions above have different properties. For instance, \(h\) is surjective (its image equals its codomain) while \(f\) is not — a distinction that only makes sense because we track the codomain as part of the function.

Connection to Computer Science

In programming, a function (or method, or procedure) takes an input and returns an output — just as our mathematical definition prescribes. The domain is the set of inputs the function accepts (its input type), and the codomain is the set of outputs it may return (its return type). The requirement that a function return exactly one value for each input is what makes functions predictable and testable: given the same input, you get the same output.

Is the codomain part of the function?

Some textbooks define a function as just a domain and a rule, without specifying a codomain in advance. In that convention, \(f(x) = x^2\) with domain \(\mathbb{R}\) is one function whether we later think of its outputs as living in \(\mathbb{R}\) or in \([0, +\infty)\).

The convention we follow includes the codomain as part of the data of a function. The reason is practical: properties like surjectivity depend on the codomain. If we omit it from the definition, we must supply it separately every time we discuss surjectivity, which is more awkward than recording it once.

There is no right or wrong here, only a choice of convention. What matters is to be consistent. In this course, a function is always a triple: domain, codomain, rule.

Exercises

Exercise 1

For each of the following rules, decide whether it defines a function from the given domain to the given codomain.

a)

\(f \colon \{1, 2, 3\} \to \{a, b\}\) defined by \(1 \mapsto a,\; 2 \mapsto b,\; 3 \mapsto a\).

Is this a function?

b)

\(g \colon \{1, 2, 3\} \to \{a, b\}\) defined by \(1 \mapsto a,\; 3 \mapsto b\).

Is this a function?

c)

\(h \colon \mathbb{R} \to \mathbb{R}\) defined by "\(h(x)\) is a number whose square is \(x\)."

Is this a function?

Exercise 2

Consider the function \(f \colon \{1, 2, 3, 4\} \to \{a, b, c, d\}\) defined by \(1 \mapsto c,\; 2 \mapsto a,\; 3 \mapsto c,\; 4 \mapsto b\).

a)

What is the image \(\mathrm{Im}(f)\)?

Exercise 3

For each pair of functions, decide whether they are equal.

a)

\(f \colon \mathbb{R} \to \mathbb{R},\; f(x) = (x+1)^2 - 1\) and \(g \colon \mathbb{R} \to \mathbb{R},\; g(x) = x^2 + 2x\).

b)

\(f \colon \mathbb{R} \to \mathbb{R},\; f(x) = |x|\) and \(g \colon [0, +\infty) \to \mathbb{R},\; g(x) = x\).

c)

\(f \colon \mathbb{R} \to \mathbb{R},\; f(x) = x^2\) and \(g \colon \mathbb{R} \to [0, +\infty),\; g(x) = x^2\).

Exercise 4

Let \(f \colon \mathbb{R} \to \mathbb{R}\) be defined by \[f(x) = \begin{cases} 2x + 1 & \text{if } x \geq 0, \\ -x & \text{if } x < 0. \end{cases}\] Compute the following values.

a)

Exercise 5

The sequence \((a_n)_{n \geq 0}\) is defined by \(a_n = 3n + 1\).

a)

Viewed as a function, what is the domain of this sequence?

b)

What is the image of this sequence (the set of values it actually takes)?

Summary

  • A function \(f \colon A \to B\) assigns to each \(a \in A\) exactly one \(f(a) \in B\).

  • The domain \(A\) is the set of inputs; the codomain \(B\) is the set in which outputs live; the image \(\mathrm{Im}(f) \subseteq B\) is the set of outputs actually produced.

  • Two functions are equal if and only if they share the same domain, the same codomain, and the same value at every point.

  • A sequence is a function \(\mathbb{N} \to \mathbb{R}\) — the general theory of functions extends everything we already know about sequences.