Functions
Master the theory of functions, including injective, surjective, and bijective functions, inverse functions, and function composition. Functions are fundamental to all of mathematics and computer science.
- Understand the formal definition of functions and related terminology
- Distinguish between injective, surjective, and bijective functions
- Prove properties of functions using formal definitions
- Find inverse functions and understand when they exist
- Compose functions and understand composition properties
- Apply functions to solve counting and mapping problems
1. Function Definitions
Let A and B be non-empty sets. A function f from A to B, denoted , is a rule that assigns to each element exactly one element .
We write and say that y is the image of x under f.
- A is called the domain of f
- B is called the codomain of f
- The set is called the range or image of f
Key Requirements for a Function:
- Every element in the domain must be mapped to something
- Each element in the domain maps to exactly one element in the codomain
- The range is a subset of the codomain:
Let and . Which of the following are functions from A to B?
1.
✓ This is a function. Every element in A is mapped to exactly one element in B.
2.
✗ Not a function. Element 3 is not mapped to anything.
3.
✗ Not a function. Element 1 is mapped to both a and b.
4.
✓ This is a function. Multiple elements can map to the same output (this is a constant function).
Two functions and are equal, written , if for all .
Identity Function:
The identity function is defined by for all .
Constant Function:
A constant function maps all elements of A to a single element : for all .
Inclusion Function:
If , the inclusion function is defined by for all .
defined by
- Domain: (all real numbers)
- Codomain:
- Range: (non-negative real numbers)
The graph of a function is the set of ordered pairs:
A relation is the graph of a function if and only if for each , there is exactly one such that .
2. Injective Functions
A function is injective (or one-to-one) if different inputs always produce different outputs.
Formally, f is injective if:
Equivalently (contrapositive):
Example 1: Is defined by injective?
Assume
Then
Subtracting 3:
Dividing by 2:
Therefore, f is injective.
Example 2: Is defined by injective?
No! Consider and :
and
We have but , so g is not injective.
Example 3: Is defined by injective?
Assume where
Then
Taking square roots (both sides non-negative):
Therefore, h is injective on the restricted domain .
Let be a function:
- If f is injective and finite, then
- If and are both injective, then is injective
- A function has a left inverse if and only if it is injective
Suppose f and g are injective. We prove is injective.
Let and assume
Then
Since g is injective,
Since f is injective,
Therefore, is injective.
3. Surjective Functions
A function is surjective (or onto) if every element of the codomain B is the image of at least one element in the domain A.
Formally, f is surjective if:
Equivalently, the range of f equals the codomain:
Example 1: Is defined by surjective?
Let be arbitrary. We need to find such that
We need
Solving for x:
This value of x is real for any real y, so every has a pre-image.
Therefore, f is surjective.
Example 2: Is defined by surjective?
No! Consider :
We need , but no real number x satisfies this equation.
Since -1 (and all negative numbers) have no pre-image, g is not surjective.
Example 3: Is defined by surjective?
Let . We need to find such that
Choose (well-defined since )
Then
Therefore, h is surjective with the restricted codomain.
Let be a function:
- If f is surjective and finite, then
- If and are both surjective, then is surjective
- A function has a right inverse if and only if it is surjective
Suppose f and g are surjective. We prove is surjective.
Let be arbitrary.
Since g is surjective, there exists such that
Since f is surjective, there exists such that
Therefore,
Since z was arbitrary, is surjective.
4. Bijective Functions
A function is bijective (or a one-to-one correspondence) if it is both injective and surjective.
A bijection establishes a perfect pairing between elements of A and elements of B.
If there exists a bijection between finite sets A and B, then .
Since f is injective,
Since f is surjective,
Therefore, .
Example 1: defined by
This is bijective (we proved it's both injective and surjective earlier).
Example 2: defined by
This is bijective:
- Injective: Different inputs map to different outputs
- Surjective: Every element in {a,b,c} is mapped to
Example 3: defined by
This is bijective on the restricted domain and codomain (check both properties).
- The composition of two bijections is a bijection
- Every bijection has an inverse function
- The inverse of a bijection is also a bijection
- The identity function is a bijection
Summary Table:
| Property | Injective | Surjective | Bijective |
|---|---|---|---|
| One-to-one | ✓ | ✗ | ✓ |
| Onto | ✗ | ✓ | ✓ |
| Has inverse | Left | Right | Two-sided |
| Cardinality (finite) |
5. Inverse Functions
Let be a bijection. The inverse function of f, denoted , is defined by:
In other words, "undoes" what f does.
A function has an inverse function if and only if f is bijective.
(⟹) Suppose exists.
To show f is injective: If , then , so .
To show f is surjective: For any , let . Then .
(⟸) Suppose f is bijective.
For each , there exists a unique such that (surjective ensures existence, injective ensures uniqueness). Define .
If is bijective with inverse , then:
- for all
- for all
- is also bijective
Example 1: Find the inverse of defined by
Solution:
Let
Solve for x in terms of y:
Therefore, , or
Verification: ✓
Example 2: Does defined by have an inverse?
No! We showed earlier that g is not injective (since ).
Therefore, by Theorem 4.5, g does not have an inverse function.
Example 3: Find the inverse of defined by
On this restricted domain, h is bijective, so it has an inverse.
Let . Solving for x (with ):
Therefore, for
6. Function Composition
Let and be functions. The composition of g and f, denoted (read "g composed with f" or "g circle f"), is the function defined by:
Note: Apply f first, then apply g to the result. The order matters!
Important:
- For to be defined, the codomain of f must match the domain of g
- In general, (composition is not commutative)
- Composition is associative:
Example 1: Let and . Find and .
Note: (they give different results)
Example 2: Let and for . Compute and .
for
Note: (identity), but on all of
Let f, g, and h be functions where composition is defined:
- Associativity:
- Identity: and where
- Inverse: If f is bijective, then and
- Inverse of Composition: If f and g are bijective, then
We show and
For any :
Similarly for the other direction. Therefore .
Think of Function Composition Like Putting on Clothes:
If = "put on socks" and = "put on shoes", then:
- = "put on socks, then shoes" (correct order)
- = "put on shoes, then socks" (incorrect order)
Similarly, to undo , you must first undo g, then undo f:
Practice Quiz
Frequently Asked Questions
What's the difference between codomain and range?
The codomain is the set that you specify as the target when defining a function.
The range (or image) is the set of actual output values that the function produces.
Example: For f: ℝ → ℝ defined by f(x) = x²:
- Codomain = ℝ (all real numbers)
- Range = [0, ∞) (only non-negative real numbers)
The function is surjective if and only if range = codomain.
How do I prove a function is injective?
Method 1 (Direct): Assume f(x₁) = f(x₂) and prove that x₁ = x₂.
Method 2 (Contrapositive): Assume x₁ ≠ x₂ and prove that f(x₁) ≠ f(x₂).
Method 3 (Horizontal Line Test): For functions on real numbers, if every horizontal line intersects the graph at most once, the function is injective.
Most commonly, we use Method 1 in formal proofs.
Why can't every function have an inverse?
An inverse function must "undo" what the original function does. For this to work:
- Injective required: If two inputs map to the same output, the inverse wouldn't know which input to return
- Surjective required: Every output must come from some input, otherwise the inverse wouldn't be defined everywhere
Example: f(x) = x² on ℝ fails both:
- Not injective: f(2) = f(-2) = 4 (which input should f⁻¹(4) return?)
- Not surjective: No input gives -1 (what should f⁻¹(-1) be?)
What does f⁻¹ mean if f is not bijective?
If f is not bijective, then f⁻¹ as an inverse function does not exist.
However, f⁻¹ can still denote the inverse image (or preimage) of a set:
(the set of inputs that map into B)
This is a different concept! The inverse image is always defined, even when the inverse function is not.
Why is (g ∘ f)⁻¹ = f⁻¹ ∘ g⁻¹ and not g⁻¹ ∘ f⁻¹?
Think about the order of operations. When you apply g ∘ f, you:
- First apply f
- Then apply g to the result
To undo this, you must:
- First undo g (apply g⁻¹)
- Then undo f (apply f⁻¹)
You undo operations in reverse order! Like putting on shoes and socks: to undo, you remove shoes first, then socks.
What's the practical importance of functions in computer science?
Functions are fundamental to CS:
- Programming: Functions/methods are the building blocks of programs
- Data structures: Hash functions (should be injective for perfect hashing)
- Cryptography: Encryption functions (should be bijective to allow decryption)
- Databases: Functional dependencies determine database design
- Algorithms: Algorithm complexity is described as a function of input size
- Type theory: Types in programming languages are sets, functions map values between types