0% found this document useful (0 votes)
4 views

Ch1 Fundamental Structure 2019

The document discusses the concept of discrete structures and sets. It defines discrete structures as abstract mathematical structures used to represent discrete objects and relationships between objects, such as sets, relations, and graphs. It then discusses what a set is, including that a set is an unordered collection of elements and ways to describe sets, such as using a roster or set builder method. It also covers set operations like union, intersection, difference, and complement.

Uploaded by

pilotbairexd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Ch1 Fundamental Structure 2019

The document discusses the concept of discrete structures and sets. It defines discrete structures as abstract mathematical structures used to represent discrete objects and relationships between objects, such as sets, relations, and graphs. It then discusses what a set is, including that a set is an unordered collection of elements and ways to describe sets, such as using a roster or set builder method. It also covers set operations like union, intersection, difference, and complement.

Uploaded by

pilotbairexd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 80

CS 114: Discrete Structures

CHAPTER 1:
FUNDAMENTAL STRUCTURES
What is Discrete Structure?

 Discrete Objects

• Separated from each other, distinct, unconnected (Opposite of


continuous).

• Examples of Discrete objects: integers, people, house.

• Examples of Continuous objects: real number.

 Discrete Structures

• The abstract mathematical structures used to represent discrete


objects and relationships between the objects e.g. sets, relations,
graphs

2
Why study discrete structures?

 It provides the mathematical foundation for many computer science

courses : Data structure, algorithm, database theory, computer


security,...etc

 Discrete structures contains the necessary mathematical background

for solving problems.

 Information is stored and manipulated by computing machines in a

discrete fashion : 010101011.

3
Sets
(In Book: Chapter 2-sec 2.1)

4
T. Mai Al-Ammar
Sets

• Set is one of the discrete structures used to represent discrete objects.


• Many important discrete structures are built using sets.
• Set Definition:
 A set is an unordered collection of objects, called the elements or members
of the set.
 A set is said to contain its elements. a A denotes that a is an element of
the set A. aA denote that a is not an element of the set A.
• e.g.A={1, 2, 3} is the set containing “1” and “2” and “3”. So, 1, 2, 3  A,
but 5  A.
 Although sets are usually used to group together elements with common
properties, there is nothing that prevents a set from having unrelated
elements , e.g. { a, 2, Ahmed, Riyadh}. 5
T. Mai Al-Ammar
Sets ( Cont. )

• Ways to describe sets :


1. Roster method: List all members of a set ,if possible, between braces. E.g.
S = { 1, 2, 3}
S = { 1, 3,5,9 … 99 } (( ellipses used ))
2. Set builder method: characterize all elements in the set by stating the
property or properties they must have to be members .
e.g. S contains all odd positive integers less than 100
+
𝑆= 𝑥∈ ℤ 𝑖𝑠 𝑜𝑑𝑑 𝑎𝑛𝑑 𝑥 < 100 }
• N = { 0,1,2,3 , … } set of Natural numbers
• Z = { … , -2, -1, 0, 1, 2, … } set of integers
• Q = { p/q | 𝑝 ∈ 𝑍 , 𝑞 ∈ 𝑍, 𝑎𝑛𝑑 𝑞 ≠ 0 } set of rational numbers

6
T. Mai Al-Ammar
Sets (Cont.)

• Sets can have other sets are members , e.g. S = { N, Z, R }


• In sets , the order of elements is not important since sets are unordered.
• In sets, the repetition is irrelevant, e.g. {1, 1, 2, 3, 3} = {1, 2, 3}
• The concept of datatype in computer science is built upon the concept
of a set, Datatype is the name of a set together with a set of operations
that can performed on objects of the set.
E.g. Data type : boolean is the name of set {0,1} and operation on it is
{ AND, OR, XOR}.

7
T. Mai Al-Ammar
Sets ( Cont. )

• Equal Sets :
• Two sets are equal if and only if they have the same elements, if A and B are
sets, then A = B if and only if ∀ 𝒙 ( 𝒙 ∈ 𝑨 ↔ 𝒙 ∈ 𝑩)
• e.g. { 1, 2,3 } = { 2 , 3, 1}
{ 1 , 2, 2, 3 } = { 1,2, 3 ,3 }
• Empty Set ( null set) :
• A set that has no elements. It is denoted by ∅ or { } . Note:   {}

• e.g. a set that contains positive integers less than zero


• Singleton Set:
• A set with one element.
• Empty set ∅ is not equal to {∅ } (( singleton set)).

8
T. Mai Al-Ammar
Sets (Cont. )

• Venn Diagram :
• Sets can be represented graphically using Venn diagrams.
• In Venn diagram, the universal set is represented as a rectangle.
• Inside rectangle, circles are used to represent sets.
• And points represent elements.

U V
a

9
T. Mai Al-Ammar
Sets (subsets and superset)

• The set A is said to be a subset of the set B if and only if every element of A is
also an element of B, and B is said to be superset of A.
• A ⊆ B if and only if ∀x(x ∈ A → x ∈ B) is true
• To show that A ⊄ B, find a single element x A such that x  B
• For every set S:  ⊆ S and S ⊆ S
A
B
 Example: Let A = {a, b, c}
B = {a, b, c, d},
C = { a, c, d, e}
then A ⊆ B , but A is not subset of C.

10
T. Mai Al-Ammar
Sets (proper subsets )

Proper subset:
 if a set A is a subset of B but AB then A B.
 for A B, it must be the case that AB is true and there must exist an
element x of B that is not an element of A:
 i.e. ∀ 𝒙 𝒙 ∈ 𝑨 → 𝒙 ∈ 𝑩 ˄ ∃ 𝒙 ( 𝒙 ∈ 𝑩˄ x ∉ A)
• A = B if AB and B A i.e. x ((x  A) <=> (x  B))

 Examples: {1, 2, 3}  {1, 2, 3, 4, 5}


{1, 2, 3}  {1, 2, 3, 4, 5}

11
T. Mai Al-Ammar
Sets ( Cont.)

Examples:
• Is {x}  {x}? No
• Is {x}  {x}? Yes
• Is {x}  {x, {x}}? Yes
• Is {x}  {x, {x}}? Yes

12
T. Mai Al-Ammar
Size of a Set

Cardinality of a set: Let S be a set. If there are exactly n distinct elements in S,


where n is a non-negative 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|.
Examples:
 Let A be the set of Arabic alphabets, then |A|=28.
 Let B is a set of odd positive integers less than 10
B = { 1, 3, 5, 7, 9 } , |B| = 5

Questions:
|Ø|=?
If B={1, 1, 1}, then |B|=?
If S = { , {}, {,{}} }, then |S|=?
13
T. Mai Al-Ammar
Sets (Cartesian Products)

The Cartesian product of A and B, denoted by A x B , is the set of all ordered


pairs (a, b) where a ∈ A and b ∈ B :
• A × B = {(a, b) | a ∈ A ∧ b ∈ B}.

• Examples:
If A={1, 2}, B={a, b, c} then A x B={(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}

• Facts:
1. A x B ≠ B x A 2. |A x B| = |A| * |B|
• A1 x A2 x … x An = {(a1, a2,…, an) | ai  Ai, for i=1, 2, …, n}
• Questions
• If P = {1,2}, then P x P x P =?
14
T. Mai Al-Ammar
Sets (power set)

Power Set :
• If S is a set, then the power set of S is the set of all subsets of the set S.
• The power set of S is denoted by P(S). i.e., P(S) = { x | x  S }.
Examples:
Ifs={0,1,2}, then P(S)={∅, {0}, {1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1, 2}}.
If S={a}, then P(S)={, {a}}.
If S = {a, b}, then P(S)={, {a}, {b}, {a, b}}.
If S = , then P(S)= {}
If S = {{}}, then P(S)= {, {{}} }

Fact:

If S is finite, |P(S)| = 2|S| . (if |S|=n, |P(S)|=2n)


15
T. Mai Al-Ammar
Set Operations
(In Book: Chapter 2-sec 2.2)

16
T. Mai Al-Ammar
Sets Operations

1. Union
2. Intersection
3. Disjoint
4. Difference
5. Complement
6. Set Identities
7. Inclusion-exclusion
8. Computer representation

17
T. Mai Al-Ammar
Set operations ( Cont.)

1. Union :
The union of two sets A and B, denoted by AB, is the set that contains
those elements that are either in A or in B, or in both:
A  B = { x | x  A or x  B}
e.g. The union of two sets {1,3,5} and { 1,2,3} is { 1, 2, 3,5, }
In the figure, the colored area (1,2, and 3) is the union of two sets.

18
T. Mai Al-Ammar
Set operations ( Cont.)

2. Intersection :
The intersection of two sets A and B, denoted by AB, is the set
containing those elements in both A and B:
A  B = { x | x  A and x  B}
e.g. the intersection of two sets {1,3,5 } and {1,2,3} is {1,3}
In the figure, the colored area (2) is the intersection of two sets.

19
T. Mai Al-Ammar
Set operations ( Cont.)

Generalized Unions and Intersections:

A1 ∪ A2 ∪ ・ ・ ・ ∪ An

A1 ∩ A2 ∩ ・ ・ ・ ∩ An

21
T. Mai Al-Ammar
Sets Operations (Cont.)

3. Disjoint sets:
Two sets are said to be disjoint if their intersection is the empty set.
Examples:

• If A = {1, 3, 5, 7, 9}, and B = {2, 4, 6, 8, 10}, then A  B=Ø

• If A = {x | x is a CS major student} and B = {x | x is a IS major


student}, then AB=Ø

22
T. Mai Al-Ammar
Sets Operations (Cont.)

4. Difference :
The difference of two sets A and B, denoted by A-B, is the set containing
those elements that are in A but not in B:
A – B = { x | xA and xB}
e.g. If A = {1, 3, 5}, and B = {1, 2, 3}, then A-B = {5}, and B-A = {2}.
In the figure, the colored area (1) is the difference of two sets.
In general : A-B  B-A

23
T. Mai Al-Ammar
Set Operations (Cont.)

5. Complement :
The Complement of the set A : is the complement of A with the
respect t0 universal set U, i.e. those elements that are in universal set
but not in A .

Therefore, the complement of the set A is U – A


e.g. If U={1, 2, …, 10}, A={1, 3, 5, 7, 9}, then Ac={2, 4, 6, 8, 10}.
In the figure, the colored area (3,4) is the complement of the first set.

24
T. Mai Al-Ammar
Set Identities
6. Set Identities

Identities Name
AU=A
Identity laws
AU=A
AUU=U
Domination laws
A=
AUA=A
Idempotent laws
AA=A
(Ac)c = A Complementation law
AUB=BUA
Commutative laws
AB=BA
A U (B U C) = (A U B) U C
Associative laws
A  (B  C) = (A  B)  C
25
T. Mai Al-Ammar
Set Identities

6. Set Identities ( Cont.) :


Identities Name
A U (B  C) = (A U B)  (A U C)
Distributive laws
A  (B U C) = (A  B) U (A U C)
(A U B)c = Ac  Bc
De Morgan’s laws
(A  B)c = Ac U Bc
A U (A  B) = A
Absorption laws
A  (A U B) = A
A U Ac = U
Complement laws
A  Ac = 

Facts:
• Uc = Ø and Øc = U
• A - B = A  Bc 26
T. Mai Al-Ammar
Set Theory – Inclusion-exclusion

Inclusion-exclusion theory: We are interested in finding cardinality of the


union sets.
Question Example:
|A| = How many people are wearing a watch?
|B| = How many people are wearing jackets?
|A  B| = How many people are wearing a watch OR jackets?
Answer:

B A Wrong or right?

27
T. Mai Al-Ammar
Set Theory – Inclusion-exclusion

Answer:
Note that |A|+|B| counts each element that is in A but not in B, or in B not in A,
exactly once. Each element that is in both A and B will be counted twice

So, elements in A  B will be subtracted the result, i.e.,


|A  B| = |A| + |B| - |A  B|

Question: Generalize the formula for 3 sets

28
T. Mai Al-Ammar
Set Theory – Inclusion-exclusion

Example:
There are 150 CS majors
CS530
100 are taking CS530 CS520

70 are taking CS520


30 are taking both

Question:
How many are taking neither?

Answer:

150 – (100 + 70 - 30) = 10


29
T. Mai Al-Ammar
Set Theory – Computer representation

Let U be a finite universal set. Let a1, a2,…, an be an arbitrary ordering of the
elements of U.
Represent a subset A of U with the bit string of length n, where

1 if ai  A
i th
bit  
0 if ai  A

Examples:
Let U={1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and then the set A={1, 3, 5, 7, 9} can be
represented by the string of bits:
10 1010 1010
The set B={1, 2, 4, 9} can be represented as:
11 0100 0010

30
T. Mai Al-Ammar
Set Theory – Computer representation

Examples:
A: 10 1010 1010
B: 11 0100 0010
• The set A U B can be represented as: 11 1110 1010
• The set A  B can be represented as: 10 0000 0010

Questions:
If C={1, 6, 8, 10}, express following sets with bit strings
A-B, Ac, A U (B  C) and A  (B U C)

31
T. Mai Al-Ammar
Relations
(In Book: Chapter 9- sec 9.1 and 9.5)

32
T. Mai Al-Ammar
Relations

Relation:

Let A and B be sets. A binary relation (R) from A to B is a subset of


A x B. i.e., R  AxB.

 A binary relation from A to B is a set R of ordered pairs where the

first element of each ordered pair comes from A and the second
element comes from B.

 a R b (a,b)  R

 a R b (a,b) ∉ R

33
T. Mai Al-Ammar
Relations- examples

Example:
Let A = Set of students; B = Set of courses, let R be the relation that
consists of pairs :
R = {(a,b) | student a is enrolled in course b}
Note that when a student is not enrolled in any course, there will be no
pairs in R that have this student as the first element.
Example :
Let A = Set of cities; B = Set of countries. Define the relation R by
specifying that (a, b) belongs to R if city a is the capital of b.
For instance, (Riyadh, Saudi Arabia), (Delhi, India), (Washington, USA)
are in R. 34
T. Mai Al-Ammar
Relations ( Cont.)

Example:

Let A={0, 1, 2} and B={a, b}. {(0, a), (0, b), (1, a), (2, b)} is a relation
from A to B. This means, 0Ra, but 1Rb.

 Relations can be represented in two ways - as shown in the figure:

 Graphically using arrows to represent ordered pairs.

 Using a table
0.
.a R a b
0 X X
1 X
1.
2 X
.b
35
T. Mai Al-Ammar 2.
Relations ( Cont.)

 A function f from a set A to B assigns exactly one element of B to each

element of A.

 Every element of A is the first element of exactly one ordered pair in

the relation.

 A relation can be used to express a one to many relationships between

the elements of the sets A and B, i.e. an element of A may be related to


more than one element of B.

 A function represents a relation where exactly one element of B is

related to each element of A, i.e. every element has only one image.

36
T. Mai Al-Ammar
Relations- on a set
Definition:

A relation on the set A is a relation from A to A. That is, a relation on a set


A is a subset of A x A.

Example:

Let A = {1, 2, 3, 4}. Which ordered pairs are in the relation

R={(a, b) | a divides b}?

(a, b) є R if and only if a and b are positive integers not exceeding 4 such
that a divides b, we see that

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

The pairs in R are displayed graphically and in tabular form:


37
T. Mai Al-Ammar
Relations ( Cont.)

The pairs in R are displayed graphically and in tabular form:

.1 1 R 1 2 3 4
.2 2. 1 X X X X
2 X X
.3 3.
3 X
.4 4. 4 X

38
T. Mai Al-Ammar
Relations ( Cont.)
Example :

Consider the 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 these relations contain each of the pairs (1, 1), (1, 2), (2, 1), (1, -
1) and (2, 2)?

(1, 1) is in R1, R3, R4 and R6; (1, 2) is in R1and R6;

(2, 1) is in R2, R5 and R6; (1, -1) is in R2, R3 and R6;

(2, 2) is in R1, R3 and R4.


39
T. Mai Al-Ammar
Relations ( Properties of Relations )

1. Reflexivity: A relation R on a set A is called reflexive if (a, a)  R for


all a  A.

2. Symmetry: A relation R on a set A is called symmetric if (b, a)  R


whenever (a, b)  R, for all a, b  A.
∀𝒂 ∀𝒃 ( 𝒂, 𝒃 ∈ 𝑹 → 𝒃, 𝒂 𝝐 𝑹 )

3. Antisymmetry: A relation R on a set A is called antisymmetric if for


all a, b  A, if (a, b)  R and (b, a)  R, then a = b.
∀𝒂 ∀𝒃 (( 𝒂, 𝒃 ∈ 𝑹 ˄ 𝒃, 𝒂 𝝐 𝑹 ) → (𝒂 = 𝒃))

The contrapositive is : ∀𝒂 ∀𝒃 ( 𝒂 ≠ 𝒃 → ( 𝒂, 𝒃 ∉ 𝑹 ˅ 𝒃, 𝒂 ∉ 𝑹 ))

40
T. Mai Al-Ammar
Relations ( Properties of Relations )

4. Transitivity: A relation R on a set A is called transitive if (a, b)  R


and (b, c)  R imply (a, c)  R, for all a, b, c  A.

Remark:
 The terms symmetric and antisymmetric are not opposites.

 A relation can have both of these properties or may lack both of them.

 A relation can not be both symmetric and antisymmetric if it contains


some pair of the form (a,b) where a b
 In antisymmetric, the only way to have a related to b and b related to a
is for a and b to be the same element.
41
T. Mai Al-Ammar
Relations ( Properties of Relations )

Example :

Which of the following relations are reflexive and symmetric?

Consider the 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},

The reflexive relations are R1 (because a ≤ a, for all integer a), R3 and R4.

For each of the other relations ,it is easy to find a pair of the form (a, a)
that is not in the relation.

42
T. Mai Al-Ammar
Relations ( Properties of Relations )

The symmetric relations are R3, R4 and R6.


R3 is symmetric, for if a=b or a=-b, then b=a or b=-a.
R4 is symmetric, since a=b implies b=a.
R6 is symmetric, since a+b ≤ 3 implies b+a ≤ 3.
None of the other relations is symmetric.

43
T. Mai Al-Ammar
Relations ( Properties of Relations )

Example :

Which of the following relations are antisymmetric? Relations 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},

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

R2 is antisymmetric, since it is impossible for 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 also antisymmetric, since it is impossible that a = b+1 and b = a+1.44


T. Mai Al-Ammar
Relations ( Properties of Relations )
Example:

Which of the following relations are transitive? Relations 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},

The transitive relations from Example 5 are R1, R2, R3 and R4.

R1 is transitive, since a ≤ b and b ≤ c imply a ≤ c.

R2 is transitive, since a > b and b > c imply a > c.

R3 is transitive, since a = ±b and b = ±c imply a = ±c.

R4 is transitive, since a = b and b = c imply a = c. 45


T. Mai Al-Ammar
Relations ( Properties of Relations )

Example :

Consider following relations on {1, 2, 3}:

R1= {(1, 1), (1, 2), (2, 1), (2, 2), (2, 3)},

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

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

R4={(2, 3)},

Which of the relations are reflexive, symmetric,

antisymmetric and transitive?

46
T. Mai Al-Ammar
Relations -Equivalence relations

Definition:

A relation on a set A is called an equivalence relation if it is


reflexive, symmetric, and transitive.

1. Reflexive ( aA, aRa)

2. Symmetric (aRb => bRa)

3. Transitive (aRb and bRc => aRc)

47
T. Mai Al-Ammar
Relations -Equivalence relations

Example :
Let R be the relation on the set of real numbers such that aRb if and only
if a-b is an integer. Is R an equivalence relation?
• As a-a = 0 is an integer for all real numbers a. So, aRa for all real
numbers a. Hence R is reflexive.
• Let aRb, then a-b is an integer, so b-a also an integer. Hence bRa, i.e., R
is symmetric.
• If aRb and bRc, then a-b and b-c are integers. So, a-c = (a-b) + (b-c) is
also an integer. Hence, aRc. Thus R is transitive.
Consequently, R is an equivalence relation
48
T. Mai Al-Ammar
Relations -Partial orderings

Definition:
A relation R on a set S is called a partial ordering or partial order if it is reflexive,
antisymmetric, and transitive.
A set S together with a partial ordering R is called a partially ordered set, or poset, and
is denoted by (S,R). Members of S are called elements of the poset

Example:
 Show that the “greater than or equal” relation (≥) is a partial ordering on the set of integers.
R= {(a, b) | a ≥ b} for all a, b,  Z
R is reflexive, since a ≥ a for every integer a
R is antisymmetric, if a ≥ b and b ≥ a, then a = b.
R is transitive because a ≥ b and b ≥ c imply that a ≥ c.
It follows that ≥ is a partial ordering on the set of integers and (Z, ≥) is a poset.

49
T. Mai Al-Ammar
Relations -Partial ordering

Example:
 Let R be the relation on the set of people such that xRy if x and y are people and
x is older than y. Show that R is not a partial ordering.

R is antisymmetric because if a person x is older than a person y, then y is not older


than x. That is, if xRy, then y Rx.
R is transitive because if person x is older than person y and y is older than person z,
then x is older than z. That is, if xRy and yRz, then xRz.
R is not reflexive, because no person is older than himself or herself. That is, xRx for
all people x.
It follows that R is not a partial ordering.

50
T. Mai Al-Ammar
Relations -Partial ordering

Definition:
The elements a and b of a poset (S, R) are called comparable if either a R b or
b R a. When a and b are elements of S such that neither a R b nor b R a, a
and b are called incomparable

Example:
 The “divides” relation on the set of positive integers is a partial ordering
(Why). Are the integers 3 and 9 comparable? Are 5 and 7 comparable? In poset
(Z+, |)?
The integers 3 and 9 are comparable, because 3 | 9.
The integers 5 and 7 are incomparable, because 5 | 7 and 7 | 5.

51
T. Mai Al-Ammar
Relations -Partial ordering

Definition:
If (S, R) is a poset and every two elements of S are comparable, S is called a
totally ordered or linearly ordered set, and R is called a total order or a
linear order. A totally ordered set is also called a chain.

Example:
 The poset (Z,≤) is totally ordered, because a ≤ b or b ≤ a whenever a and b are
integers.
 The poset (Z+, | ) is not totally ordered because it contains elements that are
incomparable, such as 5 and 7.

52
T. Mai Al-Ammar
Relations -Partial ordering

Definition:
(S, R) is a well-ordered set if it is a poset such that R is a total ordering and
every nonempty subset of S has a least element.

Example:
 The set of natural numbers is well ordered .

 The set of real numbers is totally ordered but not well ordered.

 The set of negative integers is not well ordered.

 The set of rational numbers is naturally totally ordered but not well ordered.
 (If p/q∈Q+, we can find p/(q+1) ∈ Q+ and it is less than p/q)

53
T. Mai Al-Ammar
Functions
(In Book: Chapter 2-sec 2.3)

54
T. Mai Al-Ammar
Introduction

• In many instances we assign to each element of a set a particular


element of a second set.
• E.g. if we have a set of students S={Amal, Rawan, Maha, Sara, Safia}
and a set of grads G = { A, B, C, D, F}
we can assign a grade for each student, this assignment is an example
of a function.
Amal A
Rawan B
Maha C
Sara D
F
Safia 55
T. Mai Al-Ammar S G
Functions

Definition:
• Let A and B be nonempty sets. A function f from A to B ( A  B ) is an
assignment of exactly one element of B to each element of A.
• We write f(a) = b if b is the unique element of B assigned by the
function f to the element a of A.
• Function are sometimes also called mapping or transformations.
Functions are specified in different ways :
 Explicitly state the assignment ( as example in the previous slide)
 Give a formula, e.g. 𝑓 𝑥 = 𝑥 + 1
 Use a computer program to specify a function
 Define a function in terms of a relation from A to B 56
T. Mai Al-Ammar
Functions-example

Example 3: Suppose we have


following graph:
And I ask you to
describe the red
function.
What’s the function?

Notation: f: RR,
domain codomain
f(x) = -(1/2)x - 25
f(x) = -(1/2)x - 25

57
T. Mai Al-Ammar
Functions -Image and Pre-image

Definition:
• If the function f : A  B, then A is the domain and B is the co-domain
of f.
• If f(a) = b, we say that b is the image of a and a is a pre-image of b.
• The range or image of f is the set of all images of elements of A.
• If f is a function from A to B, we say that f maps A to B.

a b=f(a)
f(a)

A f B
58
T. Mai Al-Ammar
Functions- Image and Pre-image

• To define a function, we specify its domain, codomain, and the


mapping of elements of the domain to elements in the codomain.
• Two functions are equal when they have the same domain, have the
same codomain, and map each element in the domain to the same
element in the codomain .
• If we change a domain or codomain or a mapping of a function, we
obtain a different function.

59
T. Mai Al-Ammar
Functions -Examples

Example:

What are the domain, co-domain and range of the function that assigns

grades to students?

Let G be the function that assigns grades to a student in our class.

The domain is the set {Amal, Rawan, Maha, Sara, Safia}

The co-domain is the set {A, B, C, D, F} Amal A


Rawan B
The range of G is the set {A, B, C, F}
Maha C
Sara D
F
Safia 60
T. Mai Al-Ammar
S G
Functions-Examples
Example :
Let R be the relation with ordered pairs (Amal,22), (Bdoor, 24), (Sara, 21),
(Dalal, 22), (Eman, 24) and (Fadwa, 22). Here each pair consists of a
graduate student and this student’s age. Specify a function determined by
this relation.

If f is a function specified by R, then : f(Amal)=22, f(Bdoor)= 24, f(Sara)=21,


f(Dala)=22, f(Eman)= 24, f(Fadwa)=22

Here f(X) is the age of x, where x is a student.

Domain {Amal, Bdoor, Sara, Dalal, Eman, Fadwa}

Co-domain { a | a>10 and a<90}

Range {21,22,24} 61
T. Mai Al-Ammar
Functions -Examples

Example:

Let f be the function that assigns the last two bits of a bit string of length 2
or greater to that string. For example, f(11010)=10.

The domain of f is the set of all bit strings of length 2 or greater

both the co-domain and the range are the set {00, 01, 10, 11}

Example:

Let f: ZZ assign the square of an integer to this integer.

Domain and Co-domain of f is the set of all integers

Range of f is the set of all integers that are perfect squares {0, 1, 4, 9, …}
62
T. Mai Al-Ammar
Functions ( Cont.)

 The domain and codomain of functions are often specified in computer

programs

 e.g. int MyFunction ( float x )


the domain of the function is real numbers ( float ) , and the codomain of

the function is integers.

63
T. Mai Al-Ammar
Functions ( Cont.)
Definition:

Let f1 and f2 be two functions from A to R. Then f1+ f2 and f1 f2 are also
functions from A to R defined by

(f1+f2) (x) = f1(x) + f2(x)

(f1 f2)(x) = f1 (x) f2(x)

Example :

Let f1 and f2 be two functions from R to R such that f1 (x) = x2 and f2 (x)
= x – x2. What are the functions f1+f2 , f1 f2?

(f1+f2)(x) = f1 (x) + f2 (x) = x2 + (x – x2) = x

(f1f2)(x) = f1 (x) f2(x) = x2(x – x2) = x3 – x4


64
T. Mai Al-Ammar
Functions -Injection

 A function f from the set A to the set B is said to be one-to-

one or an injunction, if and only if f(a) = f(b) implies that a =


b for all a and b in the domain of f.

a b ( f (a) = f (b)  a=b )

 A function is said to be injective if it is one-to-one.

 Taking the contrapositive of the implication in the definition:

a b (a ≠ b  f (a) ≠ f (b))

 Every b  B has at most one preimage.

 The figure presents an example of one to one function.


65
T. Mai Al-Ammar
Functions-Injection

Example :
Determine whether the function f: {a, b, c, d}  {1, 2, 3, 4, 5} with f(a) = 4,
f(b) = 5, f(c) = 1, and f(d) = 3 is injective.
The function f is one-to-one since f takes on different values at the four
elements of its domain.
Example :
Determine whether the function f : Z  Z , f (x) = x2 is injective.
The function f is not one-to-one since, for instance, f(1) = f(-1) = 1, but 1 ≠ -1.
Example :
Determine whether the function f (x) = x+1 from the set of
real numbers to itself is one-to-one.
66
T. Mai Al-Ammar
Functions- Surjection
 A function f from the set A to the set B is said to be onto or

surjection , if and only if for every element b  B, there is an


element a  A with f (a) = b.

∀𝒃 ∃𝒂 ( 𝒇 𝒂 = 𝒃)

 A function is said to be surjective if it is onto.

 Every b  B has at least one preimage.

 The figure presents an example of onto function.

67
T. Mai Al-Ammar
Functions - Surjection

Example :
Determine whether the function f: {a, b, c, d}  {1, 2, 3} with f(a) = 3, f(b) = 2, f(c)=
1, and f(d) = 3 is surjective.
The function f is onto, since three elements of the co-domain are images of elements
in the domain.
Example:
Determine whether the function f: Z  Z, f(x) = x2 is surjective.
The function f is not onto since, e.g. there is no integer x with x2 = -1.

Example :

Determine whether the function f (x) = x+1 from the set of

integers to itself is onto.


68
T. Mai Al-Ammar
Functions – Bijection
 A function f from the set A to the set B is said to be one-to-one
correspondence (bijective, an bijection), if it is both injection and
surjection.
 Every b  B has exactly one preimage.
Example:
Determine whether the function f: {a, b, c, d}  {1, 2, 3, 4} with f(a) = 4,
f(b) = 2, f(c) = 1, and f(d) = 3 is bijective.
The function f is one-to-one since no two values in the domain are
assigned the same function value. It is also onto because all four
elements of the co domain are images of elements in the domain.
Hence, f is a bijection.
69
T. Mai Al-Ammar
Some examples

70
T. Mai Al-Ammar
Functions-Questions

Q3. Suppose f: R+  R+,


f(x) = x2.
Is f one-to-one?
Is f onto?
Is f bijective?

Q4. Suppose f: R  R+,


f(x) = x2.
Is f one-to-one?
Is f onto?
Is f bijective?

71
T. Mai Al-Ammar
Functions-Questions

Q4. Suppose f: R  R, f(x) = x2.


Is f one-to-one?
Is f onto?
Is f bijective?

Q5. Let f be a function from


{a, b, c, d} to {1, 2, 3, 4} with
f(a)=4, f(a)=3, f(b)=2, f(c)=1
and f(d)=3.
Is f one-to-one?
Is f onto?
Is f bijective?
73
T. Mai Al-Ammar
Functions-Inverse functions

Definition: Let f be an one-to-one correspondence from the set A to the


set B. The inverse function of f is the function that assigns to an
element b є B the unique element a є A such that f(a) = b. The inverse
function of f is denoted by f-1. Hence, f-1(b) = a when f(a) = b.
A one-to-one correspondence is called invertible, since we can define an
inverse of this function.
A function is not invertible, if it is not one-to-one correspondence
f-1(b)
a=f-1(b) . . b=f(a)
f(a)
f-1

A f B
75
T. Mai Al-Ammar
Functions -Examples
Example 15: Find out whether the function f: {a, b, c}  {1, 2, 3} with
f(a) = 2, f(b) = 3, and f(c) = 1 is invertible. And if yes, what is its
inverse?
Sol: The function f is invertible, since it is bijective. The inverse function f-1
reverses the correspondence given by f, so f-1(1) = c, f-1(2) = a, and
f-1(3) = b
Example 16: Determine whether the function f: R  R, with f(x) = x2 is
invertible.
Sol: The function f is not one-to-one, since for instance, f(-2) = f(2) = 4,
but 2 ≠ -2.
Q5: find out whether the function f: Z  Z, with f(x) = x+1 is invertible.
And if yes, what is its inverse?
76
T. Mai Al-Ammar
Functions –Compositions of functions

Definition: - Let g:AB, and f:BC be functions. Then the composition


of f and g, denoted by f o g, is defined by (f o g)(x) = f(g(x))

Note that the composition f o g can not be defined unless the range of g is a
subset of the domain of f.

(f o g)(a)
. g(a) . f(g(a)) .
a G(a) f(g(a))
g f
A B C
fog
77
T. Mai Al-Ammar
Functions -Examples

Example 17: Let g:{a, b, c}{a, b, c} with g(a)=b, g(b)=c, g(c)=a. Also, let
f:{a, b, c}{1, 2, 3} with f(a)=3, f(b)=2, f(c)=1. What are the
compositions of f and g, i.e., (f o g), and g and f, i.e., (g o f)?
Sol: The composition f o g, is defined by
(f o g)(a) = f(g(a)) = f(b) = 2,
(f o g)(b) = f(g(b)) = f(c) = 1, and
(f o g)(c) = f(g(c)) = f(a) = 3.
Note that g o f is not defined, because the range of f is not subset of the
domain of g.

Q6: Let g:{a, b, c}{a, b, c} with g(a)=a, g(b)=b, g(c)=c. Also, let f:{a, b,
c}{1, 2, 3} with f(a)=1, f(b)=2, f(c)=3. What are the compositions (f o g)
& (g o f)?
78
T. Mai Al-Ammar
Functions -Examples

Example 18: Let f:ZZ with f(x) = 2x+3, and g:ZZ with g(x) = 3x+2.
What are the compositions (f o g) and (g o f)?
Sol: Both compositions (f o g) and (g o f) are defined. (f o g)(x) = f(g(x)) =
f(3x+2) = 2(3x+2)+3 = 6x+7, and
(g o f)(x) = g(f(x)) = g(2x+3) = 3(2x+3)+2 = 6x+11.

Definition: Let A and B be two sets and f: AB be a function. The graph
of the function f is the set of ordered pairs
{(a, b) | , a  A and f(a) = b}.

Note: The graph of f:AB is a subset of AXB.

79
T. Mai Al-Ammar
Functions -Examples

Example 19:

Graph of f(n)=2n+1 from Z to Z Graph of f(n)=n2 from Z to Z

80
T. Mai Al-Ammar
Functions -Properties

Some properties:
• f(Ø) = Ø
• f({a}) = {f(a)}
• f(A U B) = f(A) U f(B)
• f(A  B)  f(A)  f(B)
• f-1() = 
• f-1(A U B) = f-1(A) U f-1(B)
• f-1(A  B) = f-1(A)  f-1(B)

81
T. Mai Al-Ammar
Functions –Familiar functions

Polynomials: f(x) = a0xn + a1xn-1 + … + an-1x1 + anx0


Example: f(x) = x3 - 2x2 + 15
Exponentials: f(x) = cdx
Example: f(x) = 310x, f(x) = ex
Logarithms: log2 x = y, where 2y = x.
Ceiling: f(x) = x the least integer y so that x  y.
Example: 1.2 = 2; -1.2 = -1; 1 = 1
Floor: f(x) = x the greatest integer y so that x  y.
Example: 1.8 = 1; -1.8 = -2; -5 = -5
Question: what is -1.2 + 1.1 ?

82
T. Mai Al-Ammar
End of Chapter 1

83
T. Mai Al-Ammar

You might also like