MathIsimple
DM-04
Course 4

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.

Learning Objectives
  • 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

Definition 4.1: Function

Let A and B be non-empty sets. A function f from A to B, denoted f:ABf: A \to B, is a rule that assigns to each element xAx \in A exactly one element yBy \in B.

We write y=f(x)y = f(x) 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 {f(x)xA}\{f(x) \mid x \in A\} is called the range or image of f
Remark

Key Requirements for a Function:

  1. Every element in the domain must be mapped to something
  2. Each element in the domain maps to exactly one element in the codomain
  3. The range is a subset of the codomain: extrange(f)subseteqB ext{range}(f) subseteq B
Example: Functions and Non-Functions

Let A=1,2,3A = {1, 2, 3} and B=a,b,cB = {a, b, c}. Which of the following are functions from A to B?

1. f1=(1,a),(2,b),(3,c)f_1 = {(1,a), (2,b), (3,c)}

✓ This is a function. Every element in A is mapped to exactly one element in B.

2. f2=(1,a),(2,b)f_2 = {(1,a), (2,b)}

✗ Not a function. Element 3 is not mapped to anything.

3. f3=(1,a),(1,b),(2,c),(3,a)f_3 = {(1,a), (1,b), (2,c), (3,a)}

✗ Not a function. Element 1 is mapped to both a and b.

4. f4=(1,a),(2,a),(3,a)f_4 = {(1,a), (2,a), (3,a)}

✓ This is a function. Multiple elements can map to the same output (this is a constant function).

Definition 4.2: Function Equality

Two functions f:ABf: A \to B and g:ABg: A \to B are equal, written f=gf = g, if f(x)=g(x)f(x) = g(x) for all xAx \in A.

Definition 4.3: Special Functions

Identity Function:

The identity function IA:AAI_A: A \to A is defined by IA(x)=xI_A(x) = x for all xAx \in A.

Constant Function:

A constant function f:ABf: A \to B maps all elements of A to a single element cBc \in B: f(x)=cf(x) = c for all xAx \in A.

Inclusion Function:

If ABA \subseteq B, the inclusion function i:ABi: A \to B is defined by i(x)=xi(x) = x for all xAx \in A.

Example: Functions on Real Numbers

f:RRf: \mathbb{R} \to \mathbb{R} defined by f(x)=x2f(x) = x^2

  • Domain: R\mathbb{R} (all real numbers)
  • Codomain: R\mathbb{R}
  • Range: [0,)[0, \infty) (non-negative real numbers)
Definition 4.4: Graph of a Function

The graph of a function f:ABf: A \to B is the set of ordered pairs:

graph(f)={(x,f(x))xA}A×B\text{graph}(f) = \{(x, f(x)) \mid x \in A\} \subseteq A \times B

A relation RA×BR \subseteq A \times B is the graph of a function if and only if for each aAa \in A, there is exactly one bBb \in B such that (a,b)R(a,b) \in R.

2. Injective Functions

Definition 4.5: Injective Function (One-to-One)

A function f:ABf: A \to B is injective (or one-to-one) if different inputs always produce different outputs.

Formally, f is injective if:

x1,x2A,  f(x1)=f(x2)    x1=x2\forall x_1, x_2 \in A, \; f(x_1) = f(x_2) \implies x_1 = x_2

Equivalently (contrapositive):

x1,x2A,  x1x2    f(x1)f(x2)\forall x_1, x_2 \in A, \; x_1 \neq x_2 \implies f(x_1) \neq f(x_2)
Example: Testing for Injectivity

Example 1: Is f:RRf: \mathbb{R} \to \mathbb{R} defined by f(x)=2x+3f(x) = 2x + 3 injective?

Proof of f is injective

Assume f(x1)=f(x2)f(x_1) = f(x_2)

Then 2x1+3=2x2+32x_1 + 3 = 2x_2 + 3

Subtracting 3: 2x1=2x22x_1 = 2x_2

Dividing by 2: x1=x2x_1 = x_2

Therefore, f is injective.

Example 2: Is g:RRg: \mathbb{R} \to \mathbb{R} defined by g(x)=x2g(x) = x^2 injective?

No! Consider x1=2x_1 = 2 and x2=2x_2 = -2:

g(2)=4g(2) = 4 and g(2)=4g(-2) = 4

We have g(x1)=g(x2)g(x_1) = g(x_2) but x1x2x_1 \neq x_2, so g is not injective.

Example 3: Is h:[0,)Rh: [0, \infty) \to \mathbb{R} defined by h(x)=x2h(x) = x^2 injective?

Proof of h is injective

Assume h(x1)=h(x2)h(x_1) = h(x_2) where x1,x20x_1, x_2 \geq 0

Then x12=x22x_1^2 = x_2^2

Taking square roots (both sides non-negative): x1=x2x_1 = x_2

Therefore, h is injective on the restricted domain [0,)[0, \infty).

Theorem 4.1: Properties of Injective Functions

Let f:ABf: A \to B be a function:

  1. If f is injective and finite, then AB|A| \leq |B|
  2. If f:ABf: A \to B and g:BCg: B \to C are both injective, then gf:ACg \circ f: A \to C is injective
  3. A function has a left inverse if and only if it is injective
Proof of Composition of Injections

Suppose f and g are injective. We prove gfg \circ f is injective.

Let x1,x2Ax_1, x_2 \in A and assume (gf)(x1)=(gf)(x2)(g \circ f)(x_1) = (g \circ f)(x_2)

Then g(f(x1))=g(f(x2))g(f(x_1)) = g(f(x_2))

Since g is injective, f(x1)=f(x2)f(x_1) = f(x_2)

Since f is injective, x1=x2x_1 = x_2

Therefore, gfg \circ f is injective.

3. Surjective Functions

Definition 4.6: Surjective Function (Onto)

A function f:ABf: A \to B 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:

yB,  xA such that f(x)=y\forall y \in B, \; \exists x \in A \text{ such that } f(x) = y

Equivalently, the range of f equals the codomain: range(f)=B\text{range}(f) = B

Example: Testing for Surjectivity

Example 1: Is f:RRf: \mathbb{R} \to \mathbb{R} defined by f(x)=2x+3f(x) = 2x + 3 surjective?

Proof of f is surjective

Let yRy \in \mathbb{R} be arbitrary. We need to find xRx \in \mathbb{R} such that f(x)=yf(x) = y

We need 2x+3=y2x + 3 = y

Solving for x: x=y32x = \frac{y - 3}{2}

This value of x is real for any real y, so every yRy \in \mathbb{R} has a pre-image.

Therefore, f is surjective.

Example 2: Is g:RRg: \mathbb{R} \to \mathbb{R} defined by g(x)=x2g(x) = x^2 surjective?

No! Consider y=1Ry = -1 \in \mathbb{R}:

We need x2=1x^2 = -1, 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 h:R[0,)h: \mathbb{R} \to [0, \infty) defined by h(x)=x2h(x) = x^2 surjective?

Proof of h is surjective

Let y[0,)y \in [0, \infty). We need to find xRx \in \mathbb{R} such that x2=yx^2 = y

Choose x=yx = \sqrt{y} (well-defined since y0y \geq 0)

Then h(x)=(y)2=yh(x) = (\sqrt{y})^2 = y

Therefore, h is surjective with the restricted codomain.

Theorem 4.2: Properties of Surjective Functions

Let f:ABf: A \to B be a function:

  1. If f is surjective and finite, then AB|A| \geq |B|
  2. If f:ABf: A \to B and g:BCg: B \to C are both surjective, then gf:ACg \circ f: A \to C is surjective
  3. A function has a right inverse if and only if it is surjective
Proof of Composition of Surjections

Suppose f and g are surjective. We prove gfg \circ f is surjective.

Let zCz \in C be arbitrary.

Since g is surjective, there exists yBy \in B such that g(y)=zg(y) = z

Since f is surjective, there exists xAx \in A such that f(x)=yf(x) = y

Therefore, (gf)(x)=g(f(x))=g(y)=z(g \circ f)(x) = g(f(x)) = g(y) = z

Since z was arbitrary, gfg \circ f is surjective.

4. Bijective Functions

Definition 4.7: Bijective Function (One-to-One Correspondence)

A function f:ABf: A \to B 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.

Theorem 4.3: Bijection and Cardinality

If there exists a bijection f:ABf: A \to B between finite sets A and B, then A=B|A| = |B|.

Proof of Bijection implies equal cardinality

Since f is injective, AB|A| \leq |B|

Since f is surjective, AB|A| \geq |B|

Therefore, A=B|A| = |B|.

Example: Bijective Functions

Example 1: f:RRf: \mathbb{R} \to \mathbb{R} defined by f(x)=2x+3f(x) = 2x + 3

This is bijective (we proved it's both injective and surjective earlier).

Example 2: g:1,2,3oa,b,cg: {1,2,3} o {a,b,c} defined by g(1)=b,g(2)=c,g(3)=ag(1)=b, g(2)=c, g(3)=a

This is bijective:

  • Injective: Different inputs map to different outputs
  • Surjective: Every element in {a,b,c} is mapped to

Example 3: h:[0,)[0,)h: [0, \infty) \to [0, \infty) defined by h(x)=x2h(x) = x^2

This is bijective on the restricted domain and codomain (check both properties).

Theorem 4.4: Properties of Bijections
  1. The composition of two bijections is a bijection
  2. Every bijection has an inverse function
  3. The inverse of a bijection is also a bijection
  4. The identity function is a bijection
Remark

Summary Table:

PropertyInjectiveSurjectiveBijective
One-to-one
Onto
Has inverseLeftRightTwo-sided
Cardinality (finite)AB|A| \leq |B|AB|A| \geq |B|A=B|A| = |B|

5. Inverse Functions

Definition 4.8: Inverse Function

Let f:ABf: A \to B be a bijection. The inverse function of f, denoted f1:BAf^-1: B \to A, is defined by:

f^-1(y) = x \iff f(x) = y

In other words, f1f^-1 "undoes" what f does.

Theorem 4.5: Existence of Inverse

A function f:ABf: A \to B has an inverse function if and only if f is bijective.

Proof of Inverse exists iff bijective

(⟹) Suppose f1f^-1 exists.

To show f is injective: If f(x1)=f(x2)f(x_1) = f(x_2), then f1(f(x1))=f1(f(x2))f^-1(f(x_1)) = f^-1(f(x_2)), so x1=x2x_1 = x_2.

To show f is surjective: For any yBy \in B, let x=f1(y)x = f^-1(y). Then f(x)=yf(x) = y.

(⟸) Suppose f is bijective.

For each yBy \in B, there exists a unique xAx \in A such that f(x)=yf(x) = y(surjective ensures existence, injective ensures uniqueness). Define f1(y)=xf^-1(y) = x.

Theorem 4.6: Properties of Inverse Functions

If f:ABf: A \to B is bijective with inverse f1:BAf^-1: B \to A, then:

  1. f1(f(x))=xf^-1(f(x)) = x for all xAx \in A
  2. f(f1(y))=yf(f^-1(y)) = y for all yBy \in B
  3. (f1)1=f(f^-1)^-1 = f
  4. f1f^-1 is also bijective
Example: Finding Inverse Functions

Example 1: Find the inverse of f:RRf: \mathbb{R} \to \mathbb{R} defined by f(x)=3x5f(x) = 3x - 5

Solution:

Let y=f(x)=3x5y = f(x) = 3x - 5

Solve for x in terms of y:

y=3x5y = 3x - 5

y+5=3xy + 5 = 3x

x=y+53x = \frac{y + 5}{3}

Therefore, f1(y)=y+53f^{-1}(y) = \frac{y + 5}{3}, or f1(x)=x+53f^{-1}(x) = \frac{x + 5}{3}

Verification: f(f1(x))=f(x+53)=3(x+53)5=x+55=xf(f^{-1}(x)) = f(\frac{x+5}{3}) = 3(\frac{x+5}{3}) - 5 = x + 5 - 5 = x

Example 2: Does g:RRg: \mathbb{R} \to \mathbb{R} defined by g(x)=x2g(x) = x^2 have an inverse?

No! We showed earlier that g is not injective (since g(2)=g(2)=4g(2) = g(-2) = 4).

Therefore, by Theorem 4.5, g does not have an inverse function.

Example 3: Find the inverse of h:[0,)[0,)h: [0, \infty) \to [0, \infty) defined by h(x)=x2h(x) = x^2

On this restricted domain, h is bijective, so it has an inverse.

Let y=x2y = x^2. Solving for x (with x0x \geq 0): x=yx = \sqrt{y}

Therefore, h1(x)=xh^{-1}(x) = \sqrt{x} for x0x \geq 0

6. Function Composition

Definition 4.9: Function Composition

Let f:ABf: A \to B and g:BCg: B \to C be functions. The composition of g and f, denoted gfg \circ f (read "g composed with f" or "g circle f"), is the function gf:ACg \circ f: A \to Cdefined by:

(gf)(x)=g(f(x))(g \circ f)(x) = g(f(x))

Note: Apply f first, then apply g to the result. The order matters!

Remark

Important:

  • For gfg \circ f to be defined, the codomain of f must match the domain of g
  • In general, gffgg \circ f \neq f \circ g (composition is not commutative)
  • Composition is associative: (hg)f=h(gf)(h \circ g) \circ f = h \circ (g \circ f)
Example: Function Composition

Example 1: Let f(x)=x+1f(x) = x + 1 and g(x)=2xg(x) = 2x. Find (gf)(x)(g \circ f)(x) and (fg)(x)(f \circ g)(x).

(gf)(x)=g(f(x))=g(x+1)=2(x+1)=2x+2(g \circ f)(x) = g(f(x)) = g(x + 1) = 2(x + 1) = 2x + 2

(fg)(x)=f(g(x))=f(2x)=2x+1(f \circ g)(x) = f(g(x)) = f(2x) = 2x + 1

Note: gffgg \circ f \neq f \circ g (they give different results)

Example 2: Let f(x)=x2f(x) = x^2 and g(x)=xg(x) = \sqrt{x} for x0x \geq 0. Compute (gf)(x)(g \circ f)(x) and (fg)(x)(f \circ g)(x).

(gf)(x)=g(f(x))=g(x2)=x2=x(g \circ f)(x) = g(f(x)) = g(x^2) = \sqrt{x^2} = |x|

(fg)(x)=f(g(x))=f(x)=(x)2=x(f \circ g)(x) = f(g(x)) = f(\sqrt{x}) = (\sqrt{x})^2 = x for x0x \geq 0

Note: fg=If \circ g = I (identity), but gfIg \circ f \neq I on all of R\mathbb{R}

Theorem 4.7: Properties of Composition

Let f, g, and h be functions where composition is defined:

  1. Associativity: (hg)f=h(gf)(h \circ g) \circ f = h \circ (g \circ f)
  2. Identity: fIA=ff \circ I_A = f and IBf=fI_B \circ f = f where f:ABf: A \to B
  3. Inverse: If f is bijective, then f1f=IAf^-1 \circ f = I_A and ff1=IBf \circ f^-1 = I_B
  4. Inverse of Composition: If f and g are bijective, then (gf)1=f1g1(g \circ f)^-1 = f^-1 \circ g^-1
Proof of Inverse of Composition

We show (gf)(f1g1)=I(g \circ f) \circ (f^-1 \circ g^-1) = I and (f1g1)(gf)=I(f^-1 \circ g^-1) \circ (g \circ f) = I

For any xAx \in A:

((f1g1)(gf))(x)((f^-1 \circ g^-1) \circ (g \circ f))(x)

=(f1g1)(g(f(x)))= (f^-1 \circ g^-1)(g(f(x)))

=f1(g1(g(f(x))))= f^-1(g^-1(g(f(x))))

=f1(f(x))= f^-1(f(x))

=x= x

Similarly for the other direction. Therefore (gf)1=f1g1(g \circ f)^-1 = f^-1 \circ g^-1.

Note

Think of Function Composition Like Putting on Clothes:

If ff = "put on socks" and gg = "put on shoes", then:

  • (gf)(g \circ f) = "put on socks, then shoes" (correct order)
  • (fg)(f \circ g) = "put on shoes, then socks" (incorrect order)

Similarly, to undo (gf)(g \circ f), you must first undo g, then undo f: (gf)1=f1g1(g \circ f)^-1 = f^-1 \circ g^-1

Practice Quiz

Functions Quiz
10
Questions
0
Correct
0%
Accuracy
1
Which of the following relations from A={1,2,3}A = \{1, 2, 3\} to B={a,b}B = \{a, b\} is NOT a function?
Easy
Not attempted
2
Let f:RRf: \mathbb{R} \to \mathbb{R} be defined by f(x)=2x+1f(x) = 2x + 1. What is f1(5)f^{-1}(5)?
Easy
Not attempted
3
Which property makes a function one-to-one (injective)?
Medium
Not attempted
4
Let f:{1,2,3}{a,b,c,d}f: \{1,2,3\} \to \{a,b,c,d\} be defined by f(1)=a,f(2)=b,f(3)=cf(1)=a, f(2)=b, f(3)=c. Is f surjective?
Medium
Not attempted
5
If f:ABf: A \to B is bijective, which statement is always true?
Medium
Not attempted
6
Let f(x)=x2f(x) = x^2 from R\mathbb{R} to R\mathbb{R}. Which is true?
Hard
Not attempted
7
If f:ABf: A \to B and g:BCg: B \to C are both bijections, what can we say about gfg \circ f?
Hard
Not attempted
8
What is the identity function IA:AAI_A: A \to A?
Easy
Not attempted
9
If f:ABf: A \to B is injective and A=5|A| = 5, what is the minimum possible value of B|B|?
Medium
Not attempted
10
Given f(x)=3x2f(x) = 3x - 2 and g(x)=x2g(x) = x^2, what is (fg)(x)(f \circ g)(x)?
Hard
Not attempted

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:

f1(B)={xAf(x)B}f^{-1}(B) = \{x \in A \mid f(x) \in B\} (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:

  1. First apply f
  2. Then apply g to the result

To undo this, you must:

  1. First undo g (apply g⁻¹)
  2. 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