0% found this document useful (0 votes)
3 views66 pages

Lecture Notes (1)

The document discusses set theory as a foundational aspect of modern mathematics, emphasizing naive set theory to avoid paradoxes. It covers key concepts such as ordered pairs, Cartesian products, finite sets, cardinality, and relations, providing definitions and examples. The document serves as a comprehensive introduction to discrete mathematics for computer science.

Uploaded by

ahweneehere
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views66 pages

Lecture Notes (1)

The document discusses set theory as a foundational aspect of modern mathematics, emphasizing naive set theory to avoid paradoxes. It covers key concepts such as ordered pairs, Cartesian products, finite sets, cardinality, and relations, providing definitions and examples. The document serves as a comprehensive introduction to discrete mathematics for computer science.

Uploaded by

ahweneehere
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

SET THEORY

DISCRETE MATHEMATICS FOR COMPUTER SCIENCE - CSM 166


P. A. KWABI (Ph.D.)
TABLE OF CONTENTS
0

▶ INTRODUCTION

▶ ORDERED PAIR AND CARTESIAN PRODUCTS

▶ FINITE SETS, CARDINALITY AND COUNTING PRINCIPLES


CLASSES OF SETS POWER SETS AND PARTITIONS

▶ Relations

▶ Functions

P. A. KWABI (Ph.D.) SET THEORY 1/64


Table of Contents
1 INTRODUCTION

▶ INTRODUCTION

▶ ORDERED PAIR AND CARTESIAN PRODUCTS

▶ FINITE SETS, CARDINALITY AND COUNTING PRINCIPLES


CLASSES OF SETS POWER SETS AND PARTITIONS

▶ Relations

▶ Functions

P. A. KWABI (Ph.D.) SET THEORY 2/64


INTRODUCTION
1 INTRODUCTION

Set theory is generally considered to be the foundation of all modern mathematics. This
means that most mathematical objects (numbers, relations, functions, etc.) are defined in
terms of sets.
Unfortunately for engineers, set theory is not quite as simple as it seems. It turns out that
simple approaches to set theory include paradoxes (e.g., statements which are both true
and false). These paradoxes can be resolved by putting set theory in a firm axiomatic
framework, but that exercise is rather unproductive for engineers.
Instead, we adopt what is called naive set theory which rigorously defines the operations
of set theory without worrying about possible contradictions.
This approach is sufficient for most of mathematics and also acts as a stepping-stone to
more formal treatments.

P. A. KWABI (Ph.D.) SET THEORY 3/64


Table of Contents
2 ORDERED PAIR AND CARTESIAN PRODUCTS

▶ INTRODUCTION

▶ ORDERED PAIR AND CARTESIAN PRODUCTS

▶ FINITE SETS, CARDINALITY AND COUNTING PRINCIPLES


CLASSES OF SETS POWER SETS AND PARTITIONS

▶ Relations

▶ Functions

P. A. KWABI (Ph.D.) SET THEORY 4/64


ORDERED PAIR AND CARTESIAN PRODUCTS
2 ORDERED PAIR AND CARTESIAN PRODUCTS

The Cartesian product is named after René Descartes, whose formulation of analytic
geometry gave rise to the concept, which is further generalized in terms of direct product.

Figure 1: René Descartes 1596 - 1650

P. A. KWABI (Ph.D.) SET THEORY 5/64


An ordinary pair {a, b} is a set with two elements. In a set the order of the elements is
irrelevant, so {a, b} = {b, a}. If the order of the elements is relevant, then we use a
different object called ordered pair, represented (a, b).
Now (a, b) ̸= (b, a) (unless a = b). In general (a, b) = (a′ , b′ ) iff a = a′ and b = b′ .
Given two sets A, B, their Cartesian product A×B is the set of all ordered pairs (a, b) such
that a ∈ A and b ∈ B:

A × B = {(a, b)|(a ∈ A) ∧ (b ∈ B)} .

Analogously we can define triples or 3-tuples (a, b, c), 4-tuples (a, b, c, d),. . . , n-tuples
(a1 , a2 , . . . , a1 ), and the corresponding 3-fold, 4-fold,. . . , n-fold Cartesian products:

P. A. KWABI (Ph.D.) SET THEORY 6/64


A1 × A2 ×, ... × An =

{(a1 , a2 , ..., an )|(a1 ∈ A1 ) ∧ (a2 ∈ A2 ) ∧ ... ∧ (an ∈ An )} .


If all the sets in a Cartesian product are the same, then we can use an exponent:
A2 = A × A, A3 = A × A × A, etc. In general:
ntimes
z }| {
n
A = A × A × ... × A.

An example of Cartesian product is the real plane R2 , where R is the set of real numbers
(R is sometimes called real line)

P. A. KWABI (Ph.D.) SET THEORY 7/64


Example
If A = {a, b}, then the set of all 3-tuples from A is given by
A3 = {(a, a, a), (a, a, b), (a, b, a), (a, b, b), (b, a, a), (b, a, b), (b, b, a), (b, b, b)} .

P. A. KWABI (Ph.D.) SET THEORY 8/64


Table of Contents
3 FINITE SETS, CARDINALITY AND COUNTING PRINCIPLES

▶ INTRODUCTION

▶ ORDERED PAIR AND CARTESIAN PRODUCTS

▶ FINITE SETS, CARDINALITY AND COUNTING PRINCIPLES


CLASSES OF SETS POWER SETS AND PARTITIONS

▶ Relations

▶ Functions

P. A. KWABI (Ph.D.) SET THEORY 9/64


FINITE SETS AND COUNTABILITY
3 FINITE SETS, CARDINALITY AND COUNTING PRINCIPLES

Definition
Let S be a set. If there are exactly n distinct elements in S where n is a nonnegative
integer, we say that S is a finite set and that n is the cardinality of S. The cardinality of S
is denoted by |S|.
Remark : The term cardinality comes from the common usage of the term cardinal
number as the size of a finite set.
Example
Let A be the set of odd positive integers less than 10. Then |A| = 5.

Example
Let S be the set of letters in the English alphabet. Then |S| = 26.

P. A. KWABI (Ph.D.) SET THEORY 10/64


FINITE SETS AND COUNTABILITY
3 FINITE SETS, CARDINALITY AND COUNTING PRINCIPLES

Every set falls withing these two categories; finite and infinite.
Definition
A set S is said to be finite provided either it is empty or there is a natural number n for
which S is equipotent to {1, ..., n}; otherwise S is infinite. If S is said to be equipotent to
1, 2, ..., n it means S is one-to-one to the set.
We say that, S is countably infinite provided S is equipotent to the set N of natural
numbers. A set that is either finite or countably infinite is said to be countable. A set that
is not countable is called uncountable.

If a set is equipotent to a countable set, then it is countable.

P. A. KWABI (Ph.D.) SET THEORY 11/64


Examples
1. The set of rational numbers is countably infinite while the set of real numbers is
uncountably infinite.
2. The set A of the letters of the English alphabet and the set D of the days of the week
are finite sets. Specifically, A has 26 elements and D has 7 elements.
3. Let E be the set of even positive integers, and let I be the unit interval, that is,
E = {2, 4, 6, ...} and I = [0, 1] = {x|0 ≤ x ≤ 1}
Then both E and I are infinite.

P. A. KWABI (Ph.D.) SET THEORY 12/64


Counting Elements in Finite Sets
3 FINITE SETS, CARDINALITY AND COUNTING PRINCIPLES

Definition
The number of elements in a set is known as the cardinality of the set.
The notation n(S) or ∥S∥ will denote the number of elements in a set S. (Some texts use
#(S) or card(S) instead of n(S).) Thus n(A) = 26, where A is the letters in the English
alphabet, and n(D) = 7, where D is the days of the week. Also n(ϕ) = 0 since the empty
set has no elements.

The following lemma applies.

P. A. KWABI (Ph.D.) SET THEORY 13/64


Lemma
Suppose A and B are finite disjoint sets. Then A ∪ B is finite and

n(A ∪ B) = n(A) + n(B)

This lemma may be restated as follows:

Lemma
Suppose S is the disjoint union of finite sets A and B. Then S is finite and

n(S) = n(A) + n(B)

P. A. KWABI (Ph.D.) SET THEORY 14/64


For any sets A and B, the set A is the disjoint union of A\B and A ∩ B. Thus the previous
lemma gives us the following useful result.
Corollary
Let A and B be finite sets. Then

n(A\B) = n(A) − n(A ∩ B)

For example, suppose an art class A has 25 students and 10 of them are taking a biology
class B. Then the number of students in class A which are not in class B is:

n(A\B) = n(A) − n(A ∩ B) = 25 − 10 = 15

P. A. KWABI (Ph.D.) SET THEORY 15/64


Corollary
Let A be a subset of a finite universal set U. Then

n(Ac ) = n(U ) − n(A)

P. A. KWABI (Ph.D.) SET THEORY 16/64


CLASSES OF SETS
3 FINITE SETS, CARDINALITY AND COUNTING PRINCIPLES

Definition
Suppose S = {a, b, c, d}, then

A = [{a, b, c} {a, b, d} {a, c, d} {b, c, d}]

is said to be a class of subsets of S. Thus the elements of A are


{a, b, c} , {a, b, d} , {a, c, d} , {b, c, d}.
Let B be the class of subsets of S, each which contains b and two other elements of S. Then

B = [{a, b, c} , {a, b, d} , {b, c, d}]

The elements of B are the sets {a, b, c} , {a, b, d} , {a, c, d}. Thus B is a subclass of A,
since every element of B is also an element of A.

P. A. KWABI (Ph.D.) SET THEORY 17/64


Power Sets
3 FINITE SETS, CARDINALITY AND COUNTING PRINCIPLES

Definition
Given a set S, the classes of all subsets of S is called the power set of S denoted by P(S).
The number of elements in P(S) is determined by 2 raised to the power n(S). That is,

n(P(S)) = 2n(S)

EXAMPLE
Given that S = {1, 2, 3}. Then

P(S) = [ϕ, {1} , {2} , {3} , {1, 2} , {1, 3} , {2, 3} , S]

Note that the empty set ϕ belongs to P(S) since ϕ is a subset of S. Similarly, S belongs to
P(S). As expected from the above remark, P(S) has 23 = 8 elements.

P. A. KWABI (Ph.D.) SET THEORY 18/64


Example
What is the power set of the empty set? What is the power set of the set {ϕ}?

Solution: The empty set has exactly one subset, namely, itself. Consequently,

P(ϕ) = {ϕ} .

The set {ϕ}? has exactly two subsets, namely, ϕ and the set {ϕ} itself. Therefore,

P({ϕ}) = ϕ, {ϕ}.

P. A. KWABI (Ph.D.) SET THEORY 19/64


Partitions
3 FINITE SETS, CARDINALITY AND COUNTING PRINCIPLES

Definition
Let S be a nonempty set. A partition of S is a subdivision of S into nonoverlapping,
nonempty subsets. Precisely, a partition of S is a collection Ai of nonempty subsets of S
such that:
1. Each a in S belongs to one of the Ai .
2. The sets of {Ai } are mutually disjoint; that is, if

Aj ̸= Ak then Aj ∩ Ak = ϕ

The subsets in a partition are called cells. Figure 8 is a Venn diagram of a partition of the
rectangular set S of points into five cells, A1 , A2 , A3 , A4 , A5 .

P. A. KWABI (Ph.D.) SET THEORY 20/64


Set Theory
3 FINITE SETS, CARDINALITY AND COUNTING PRINCIPLES

Partitions

Figure 2: 8
P. A. KWABI (Ph.D.) SET THEORY 21/64
EXERCISE
Consider the following collections of subsets of S = {1, 2, ..., 8, 9}:
1. [{1, 3, 5} , {2, 6} , {4, 8, 9}]
2. [{1, 3, 5} , {2, 4, 6, 8} , {5, 7, 9}]
3. [{1, 3, 5} , {2, 4, 6, 8} , {7, 9}]
Verify as to whether each of them is a partition of S or not.

P. A. KWABI (Ph.D.) SET THEORY 22/64


Table of Contents
4 Relations

▶ INTRODUCTION

▶ ORDERED PAIR AND CARTESIAN PRODUCTS

▶ FINITE SETS, CARDINALITY AND COUNTING PRINCIPLES


CLASSES OF SETS POWER SETS AND PARTITIONS

▶ Relations

▶ Functions

P. A. KWABI (Ph.D.) SET THEORY 23/64


Introduction to Relations
4 Relations

• Why Relations? Model relationships in databases, scheduling, and networks.


• Relevance: Database joins, task dependencies.
• Application: Task scheduling in a Kumasi factory.

P. A. KWABI (Ph.D.) SET THEORY 24/64


Definition of a Relation
4 Relations

Definition
A relation R from set A to set B is a subset of A × B.

Example
Let A = {tasks}, B = {tasks}. R = {(a, b) | a precedes b}.

P. A. KWABI (Ph.D.) SET THEORY 25/64


Properties of Relations
4 Relations

• Reflexive: (a, a) ∈ R for all a ∈ A.


• Symmetric: If (a, b) ∈ R, then (b, a) ∈ R.
• Transitive: If (a, b) ∈ R and (b, c) ∈ R, then (a, c) ∈ R.
• Antisymmetric: If (a, b) ∈ R and (b, a) ∈ R, then a = b.

P. A. KWABI (Ph.D.) SET THEORY 26/64


Examples on Properties of Relations
4 Relations

EXAMPLE 1
Consider these relations on the set of integers:

R1 = {(a, b)|a ≤ b},


R2 = {(a, b)|a > b},
R3 = {(a, b)|a = b or a = −b},
R4 = {(a, b)|a = b},
R5 = {(a, b)|a = b + 1},
R6 = {(a, b)|a + b ≤ 3}.
Which of the above relations are Reflexive, Symmetric, Transitive, and Antisymmetric?
P. A. KWABI (Ph.D.) SET THEORY 27/64
Examples on Properties of Relations
4 Relations

SOLUTION TO EXAMPLE 1 Cont.


• The reflexive relations are R1 (because a ≤ a for every integer a), R3 , and R4 . For
each of the other relations in this example it is easy to find a pair of the form (a, a)
that is not in the relation.

• The relations R3 , R4 , and R6 are symmetric. R3 is symmetric, for if a = b or a = −b,


then b = a or b = −a. R4 is symmetric because a = b implies that b = a. R6 is
symmetric because a + b ≤ 3 implies that b + a ≤ 3.

QUESTION: Now, why is R1 , R2 , and R5 not symmetric?

P. A. KWABI (Ph.D.) SET THEORY 28/64


Examples on Properties of Relations
4 Relations

SOLUTION TO EXAMPLE 1 Cont.


• The relations R1 , R2 , R3 , and R4 are transitive.
R1 is transitive because a ≤ b and b ≤ c imply that a ≤ c.

R2 is transitive because a > b and b > c imply that a > c.

R3 is transitive because a = ±b and b = ±c imply that a = ±c.

R4 is clearly transitive, can you tell why?.

R5 is not transitive because (2, 1) and (1, 0) belong to R5 , but (2, 0) does not.

R6 is not transitive because (2, 1) and (1, 2) belong to R6 , but (2, 2) does not.
P. A. KWABI (Ph.D.) SET THEORY 29/64
Examples on Properties of Relations
4 Relations

SOLUTION TO EXAMPLE 1 Cont.


• The relations R1 , R2 , R4 , and R5 are antisymmetric.

R1 is antisymmetric because the inequalities a ≤ b and b ≤ a imply that a = b.

R2 is antisymmetric because it is impossible that a > b and b > a.

R4 is antisymmetric, because two elements are related with respect to R4 if and only
if they are equal.

R5 is antisymmetric because it is impossible that a = b + 1 and b = a + 1.

QUESTION: Why is R3 and R6 not antisymmetric?.


P. A. KWABI (Ph.D.) SET THEORY 30/64
Examples on Properties of Relations
4 Relations
EXAMPLE 2
Consider these relations on the set of integers:
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)}

R2 = {(1, 1), (1, 2), (2, 1)},

R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)},

R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)},

R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)},

R6 = {(3, 4)}.
Which of the above relations are Reflexive, Symmetric, Transitive, and Antisymmetric?
P. A. KWABI (Ph.D.) SET THEORY 31/64
Examples on Properties of Relations
4 Relations

SOLUTION TO EXAMPLE 2
• The relations R3 and R5 are reflexive because they both contain all pairs of the form
(a, a), namely, (1, 1), (2, 2), (3, 3), and (4, 4).

The other relations are not reflexive because they do not contain all of these ordered
pairs. In particular, R1 , R2 , R4 , and R6 are not reflexive because (3, 3) is not in any
of these relations.

P. A. KWABI (Ph.D.) SET THEORY 32/64


Examples on Properties of Relations
4 Relations

SOLUTION TO EXAMPLE 2 Cont.


• The relations R2 and R3 are symmetric, because in each case (b, a) belongs to the
relation whenever (a, b) does.

For R2 , the only thing to check is that both (2, 1) and (1, 2) are in the relation.

For R3 , it is necessary to check that both (1, 2) and (2, 1) belong to the relation, and
(1, 4) and (4, 1) belong to the relation.

QUESTION: Verify that none of the other relations is symmetric.

P. A. KWABI (Ph.D.) SET THEORY 33/64


Examples on Properties of Relations
4 Relations

SOLUTION TO EXAMPLE 2 Cont.


• R4 , R5 , and R6 are transitive. For each of these relations, we can show that it is
transitive by verifying that if (a, b) and (b, c) belong to this relation, then (a, c) also
does.

For instance, R4 is transitive, because (3, 2) and (2, 1), (4, 2) and (2, 1), (4, 3) and
(3, 1), and (4, 3) and (3, 2) are the only such sets of pairs, and (3, 1), (4, 1), and
(4, 2) belong to R4 .

QUESTION: Verify that R5 and R6 are transitive.

R1 is not transitive because (3, 4) and (4, 1) belong to R1 , but (3, 1) does not.

P. A. KWABI (Ph.D.) SET THEORY 34/64


Examples on Properties of Relations
4 Relations

SOLUTION TO EXAMPLE 2 Cont.


• R2 is not transitive because (2, 1) and (1, 2) belong to R2 , but (2, 2) does not.

R3 is not transitive because (4, 1) and (1, 2) belong to R3 , but (4, 2) does not.

• R4 , R5 , and R6 are all antisymmetric. For each of these relations there is no pair of
elements a and b with a ̸= b such that both (a, b) and (b, a) belong to the relation.

QUESTION: Verify that none of the other relations is antisymmetric.


This is done by finding a pair (a, b) with a ̸= b such that (a, b) and (b, a) are both in
the relation.

P. A. KWABI (Ph.D.) SET THEORY 35/64


Equivalence Relations
4 Relations

Definition
A relation is an equivalence relation if it is reflexive, symmetric, and transitive.

Example
Group KNUST students by region: (a, b) ∈ R if a and b are from the same region.

P. A. KWABI (Ph.D.) SET THEORY 36/64


Solved Example 1: Equivalence Relation
4 Relations

Example
Is R = {(x, y) | x, y ∈ Z, x ≡ y (mod 3)} an equivalence relation?
• Reflexive: x ≡ x (mod 3) (True).
• Symmetric: If x ≡ y (mod 3), then y ≡ x (mod 3) (True).
• Transitive: If x ≡ y (mod 3) and y ≡ z (mod 3), then x ≡ z (mod 3) (True).
• Answer: Yes.

P. A. KWABI (Ph.D.) SET THEORY 37/64


Partial Orders
4 Relations

Definition
A relation is a partial order if it is reflexive, antisymmetric, and transitive.

Example
Task scheduling: (a, b) ∈ R if task a must precede b in a Ghanaian factory.

P. A. KWABI (Ph.D.) SET THEORY 38/64


Solved Example 2: Partial Order
4 Relations

Example
Is R = {(x, y) | x ≤ y} on R a partial order?
• Reflexive: x ≤ x (True).
• Antisymmetric: If x ≤ y and y ≤ x, then x = y (True).
• Transitive: If x ≤ y and y ≤ z, then x ≤ z (True).
• Answer: Yes.

P. A. KWABI (Ph.D.) SET THEORY 39/64


CS Application: Database Joins
4 Relations

• Relations model database joins, e.g., linking customers to orders in Jumia Ghana.
def join_tables ( customers , orders ) :
return [( c , o ) for c in customers for o in orders if c .
id == o . customer_id ]

P. A. KWABI (Ph.D.) SET THEORY 40/64


Solved Example 3: Database Relation
4 Relations

Example
Define a relation R on customers and orders where (c, o) ∈ R if customer c placed order
o.
• Is it reflexive? No, a customer doesn’t place an order with themselves.
• Is it symmetric? No, (c, o) ̸ =⇒ (o, c).

P. A. KWABI (Ph.D.) SET THEORY 41/64


Exercise 1: Equivalence Relation
4 Relations

Problem
Is R = {(x, y) | x, y ∈ Z, x + y is even} an equivalence relation?

P. A. KWABI (Ph.D.) SET THEORY 42/64


Exercise 2: Partial Order
4 Relations

Problem
Is R = {(x, y) | x divides y} on Z+ a partial order?

P. A. KWABI (Ph.D.) SET THEORY 43/64


Exercise 3: Application
4 Relations

Problem
Define a relation for KNUST students where (a, b) ∈ R if a and b are in the same
department. Is it an equivalence relation?

P. A. KWABI (Ph.D.) SET THEORY 44/64


Exercise 4: Coding
4 Relations

Problem
Write a Python function to check if a relation on tasks (e.g., precedence in a Ghanaian
factory) is transitive.

P. A. KWABI (Ph.D.) SET THEORY 45/64


Exercise 5: Database
4 Relations

Problem
Model a relation linking KNUST students to courses. Is it reflexive, symmetric, or transitive?

P. A. KWABI (Ph.D.) SET THEORY 46/64


Wrap-Up: Relations
4 Relations

• Key Concepts: Equivalence relations, partial orders, database applications.


• CS Applications: Scheduling, database joins.
• : Combinatorics for counting and optimization.

P. A. KWABI (Ph.D.) SET THEORY 47/64


Table of Contents
5 Functions

▶ INTRODUCTION

▶ ORDERED PAIR AND CARTESIAN PRODUCTS

▶ FINITE SETS, CARDINALITY AND COUNTING PRINCIPLES


CLASSES OF SETS POWER SETS AND PARTITIONS

▶ Relations

▶ Functions

P. A. KWABI (Ph.D.) SET THEORY 48/64


Introduction to Functions
5 Functions

• Why Functions? Model input-output mappings in algorithms, hashing, and data


processing.
• Relevance: Hash functions, database mappings, algorithm design.
• Application: Model Ghana’s voter ID system as a function.

P. A. KWABI (Ph.D.) SET THEORY 49/64


Definition of a Function
5 Functions

Definition
A function f : A → B assigns each element of set A (domain) to exactly one element of
set B (codomain).

• Notation: f (a) = b, where a ∈ A, b ∈ B.


• Example: f : Students → IDs, f (student) = unique ID.

P. A. KWABI (Ph.D.) SET THEORY 50/64


Types of Functions
5 Functions

• Injective: One-to-one, no two elements map to the same output.


• Surjective: Onto, every element in codomain is mapped to.
• Bijective: Both injective and surjective.

P. A. KWABI (Ph.D.) SET THEORY 51/64


Example: Voter ID System
5 Functions

Example
Let A = {citizens}, B = {ID numbers}. Define f : A → B as f (citizen) = unique ID.
• Injective? Yes, each citizen has a unique ID.
• Surjective? Yes, if all IDs are assigned.
• Bijective? Yes, one-to-one correspondence.

P. A. KWABI (Ph.D.) SET THEORY 52/64


Solved Example 1: Function Properties
5 Functions

Example
Is f : R → R, f (x) = x2 injective, surjective, or bijective?
• Injective: No, f (2) = f (−2) = 4.

• Surjective: No, no x maps to −1 (no real −1).
• Bijective: No, neither injective nor surjective.

P. A. KWABI (Ph.D.) SET THEORY 53/64


Function Composition
5 Functions

Definition
For functions f : B → C and g : A → B, the composition (f ◦ g)(x) = f (g(x)).

Example
Let g : Students → Regions, g(student) = region, and f : Regions → Codes,
f (region) = code. Then (f ◦ g)(student) = code.

P. A. KWABI (Ph.D.) SET THEORY 54/64


Solved Example 2: Composition
5 Functions

Example
Let f (x) = x + 1, g(x) = x2 . Compute (f ◦ g)(x) and (g ◦ f )(x).
• (f ◦ g)(x) = f (g(x)) = f (x2 ) = x2 + 1.
• (g ◦ f )(x) = g(f (x)) = g(x + 1) = (x + 1)2 .

P. A. KWABI (Ph.D.) SET THEORY 55/64


Inverse Functions
5 Functions

Theorem
A function f : A → B has an inverse f −1 : B → A if and only if f is bijective.

Example
For f : Citizens → IDs, f −1 (ID) = citizen.

P. A. KWABI (Ph.D.) SET THEORY 56/64


CS Application: Hash Functions
5 Functions

• Hash Function: Maps data to fixed-size values, e.g., for KNUST student database.
• Goal: Ideally injective to avoid collisions.
def hash_id ( student_id ) :
return student_id % 100 # Maps to 0 -99

P. A. KWABI (Ph.D.) SET THEORY 57/64


Solved Example 3: Hash Function
5 Functions

Example
Design a hash function for KNUST student IDs: f (ID) = ID mod 10.
• Input: ID = 12345. Output: 12345 mod 10 = 5.
• Is it injective? No, IDs 12345 and 12355 map to 5.

P. A. KWABI (Ph.D.) SET THEORY 58/64


Exercise 1: Function Types
5 Functions

Problem
Is f : Z → Z, f (x) = 2x injective? Surjective?

P. A. KWABI (Ph.D.) SET THEORY 59/64


Exercise 2: Composition
5 Functions

Problem
Let f (x) = 3x, g(x) = x − 2. Compute (f ◦ g)(x) and (g ◦ f )(x).

P. A. KWABI (Ph.D.) SET THEORY 60/64


Exercise 3: Application
5 Functions

Problem
Define a function to map Ghanaian voters to polling stations. Is it injective? Surjective?

P. A. KWABI (Ph.D.) SET THEORY 61/64


Exercise 4: Coding
5 Functions

Problem
Write a Python function to map KNUST student IDs to department codes (e.g., 1 for CS, 2
for Math).

P. A. KWABI (Ph.D.) SET THEORY 62/64


Exercise 5: Inverse
5 Functions

Problem
For f (x) = 2x + 1 from R → R, find f −1 (x).

P. A. KWABI (Ph.D.) SET THEORY 63/64


Wrap-Up: Functions
5 Functions

• Key Concepts: Injective, surjective, bijective, composition, inverse.


• CS Applications: Hashing, database mappings.
• : Relations and their role in databases and scheduling.

P. A. KWABI (Ph.D.) SET THEORY 64/64


Week 4: Relations ( 16 slides)

P. A. KWABI (Ph.D.) SET THEORY 64/64

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy