Functions and Their Types
3079 words
15 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Functions and Their Types ## 🎯 Learning Objectives By the end of this topic, you will be able to: 1. **Distinguish** a function from a general relation using the one-input-one-output rule 2.

Functions and Their Types
🎯 Learning Objectives
By the end of this topic, you will be able to:
- Distinguish a function from a general relation using the one-input-one-output rule
- Identify the domain, codomain, and range of a function
- Determine whether a function is injective, surjective, or bijective
- Apply the vertical line test to graphs
- Compute function values, including piecewise-defined functions
- Perform arithmetic operations on functions
📋 Prerequisites
- Sets and Set Operations — sets, elements, set-builder notation
- Relations — binary relations, domain, range, ordered pairs
📖 Core Content
3.1 Intuition: What Is a Function?
A function is a machine that takes an input and produces exactly one output. You put a number into the "square" machine, and it spits back its square. The machine is deterministic: same input always gives same output.
Think of a vending machine: you press one button (input), and exactly one item comes out (output). If pressing B3 sometimes gives chips and sometimes gives chocolate, it's not a functioning machine!
💡 Why this matters: Functions are the building blocks of all mathematical modeling. In data science: every ML model is a function (features → prediction), every transformation (normalize, scale, log-transform) is a function, every database query (SQLSELECT) defines a function. (Diagram)
3.2 Formal Definition
3.2.1 Definition
Let A and B be non-empty sets. A function f from A to B, written f:A→B, is a relation f⊆A×B such that:
- Total: For every a∈A, there exists b∈B with (a,b)∈f.
- Single-valued: If (a,b1)∈f and (a,b2)∈f, then b1=b2. If (a,b)∈f, we write f(a)=b.
- Domain: The set A (all possible inputs)
- Codomain: The set B (all possible outputs, declared)
- Range (Image): {f(a)∣a∈A}⊆B (actual outputs)
⚠️ Key point: All functions are relations, but not all relations are functions. A relation fails to be a function if some input has no output (not total) or some input has multiple outputs (not single-valued).
3.2.2 Worked Examples
Example 1.1 (Easy): Determine if f(x)=x2 is a function from R to R.
Step 1 — Total: For every real x, x2 is a real number. ✓
Step 2 — Single-valued: Each x maps to exactly one x2. ✓
Domain: R, Codomain: R, Range: {y∈R∣y≥0}=[0,∞)
Example 1.2 (Medium): Is y2=x a function y=f(x) from R to R?
Step 1: For x=4, y2=4⟹y=2 or y=−2.
This violates the single-valued condition — one input gives two outputs.
Example 1.3 (Hard): Define f:Z→Z by f(n)=⌊n/2⌋. Is this a function? Find its range.
Step 1 — Total: Every integer n divided by 2 has a floor. ✓
Step 2 — Single-valued: Floor gives exactly one integer. ✓
Range: For n=0, f(0)=0; n=1, f(1)=0; n=2, f(2)=1; n=3, f(3)=1; negative numbers follow similarly.
Range = Z (all integers appear: f(2k)=k, f(2k+1)=k).
3.3 Domain and Range
3.3.1 Finding Domain and Range
The domain of a function is the set of all valid inputs. The range is the set of all possible outputs.
Recipe for domain:
- Look for "problem" operations: division by zero, square roots of negatives, log of non-positive
- Exclude values that cause these problems Recipe for range:
- Determine the set of outputs the function produces
- Use graphs, inequalities, or algebraic analysis
3.3.2 Worked Examples
Example 2.1: Find the domain of f(x)=x−31.
Step 1: Problem: denominator x−3=0 → undefined
Step 2: Exclude x=3
Domain: R∖{3} or (−∞,3)∪(3,∞)
Example 2.2: Find the domain of g(x)=5−x.
Step 1: Problem: square root of negative → undefined
Step 2: Need 5−x≥0⟹x≤5
Domain: (−∞,5]
Example 2.3: Find the domain and range of h(x)=x2+11.
Step 1 — Domain: Denominator x2+1≥1>0 for all real x. No problems.
Domain: R
Step 2 — Range: x2+1≥1, so x2+11≤1. Also always positive.
0<h(x)≤1
Range: (0,1]
3.4 Piecewise Functions
A piecewise function uses different rules for different parts of the domain.
x^2 & \text{if } x < 0 \\ 2x + 1 & \text{if } x \geq 0 \end{cases}
\begin{aligned} (f + g)(x) &= f(x) + g(x) \\ (f - g)(x) &= f(x) - g(x) \\ (f \cdot g)(x) &= f(x) \cdot g(x) \\ \left(\frac{f}{g}\right)(x) &= \frac{f(x)}{g(x)},\quad g(x) \neq 0 \end{aligned}
\boxed{\text{No — not defined for negative inputs}}
\boxed{(-\infty, -2) \cup (-2, 2) \cup (2, \infty)}
\boxed{\text{Bijective}}
\boxed{\text{No — not injective}}
\boxed{(0, \frac{3}{2}]}
\boxed{f(-1) = 0,\ f(2) = 2,\ f(5) = 11}
\boxed{30}
\boxed{\text{Bijective}}
\boxed{\text{No — 1 is not in the range}}
\boxed{\text{Bijective}}
\boxed{(-3, 3)}
\boxed{\text{No — pigeonhole principle}}$$ --- ## 🔗 Cross-References - Previous topic: [Relations](/courses/bsma1001/notes/sets-relations)%20%E2%80%94%20functions%20are%20special%20relations%20-%20Next%20topic%3A%20%5C%5BCoordinate%20Geometry%5C%5D(..%2Fweek02%2Fgeom-coordinate-geometry) — plotting functions geometrically - Deep dive: [Exponential Functions](/courses/bsma1001/notes/.%2Fweek05%2Ffunctions-exponential), [Composite & Inverse Functions](/courses/bsma1001/notes/.%2Fweek05%2Ffunctions-composite-inverse) in Week 5 - Across courses: BSMA1002 Stats 1 (probability distributions are functions); BSMA1003 Maths 2 (linear transformations are functions)
Join Discord
Previous1.2 RelationsNext2.1 Coordinate Geometry