0% found this document useful (0 votes)
25 views79 pages

2 - Fundemental Structure

‏تراكيب محددة واحد
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)
25 views79 pages

2 - Fundemental Structure

‏تراكيب محددة واحد
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/ 79

CS 1100: Discrete Structures

CHAPTER 2:
FU ND AM ENTAL STRU CTU RES
Sets
(In Book: Chapter 2-sec 2.1)

2
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}. 3
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
: and | are read
+
“such that” or
𝑆= 𝑥∈ ℤ 𝑖𝑠 𝑜𝑑𝑑 𝑎𝑛𝑑 𝑥 < 100 } “where”
• 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

4
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}.

5
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)).

6
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

7
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.

8
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}

9
Sets ( Cont.)

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

10
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|=?
11
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 =?
12
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)


13
Set Operations
(In Book: Chapter 2-sec 2.2)

14
Sets Operations

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

15
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.

16
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.

17
Set operations ( Cont.)

Generalized Unions and Intersections:

A1 ∪ A2 ∪ ・ ・ ・ ∪ An

A1 ∩ A2 ∩ ・ ・ ・ ∩ An

19
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=Ø

20
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

21
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.

22
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
23
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  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
24
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?

25
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

26
Set Theory – Inclusion-exclusion

Example:
There are 150 CS majors
CS530 CS520
100 are taking CS530
70 are taking CS520
30 are taking both

Question:
How many are taking neither?

Answer:

150 – (100 + 70 - 30) = 10


27
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

28
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)

29
Relations
(In Book: Chapter 9- sec 9.1 and 9.5)

30
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

31
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. 32
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. 0.

➢ Using a table .a

R a b
0 X X 1.
1 X .b
2 X 2.

33
Relations ( Cont.)

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:

.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

34
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:


36
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.
37
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 : ∀𝒂 ∀𝒃 ( 𝒂 ≠ 𝒃 → ( 𝒂, 𝒃 ∉ 𝑹 ˅ 𝒃, 𝒂 ∉ 𝑹 ))

38
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.
39
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.

40
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.

41
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 R 4 if


and only if they are equal.
R5 is also antisymmetric, since it is impossible that a = b+1 and b = a+1.
42
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. 43


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?

44
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)

45
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
46
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.
𝒃
Question: Is the “divides” relation on Z+ a partial ordering, poset (Z+, |)? a | b 𝒂
= integer
Question: Is the “divides” relation on Z a partial ordering, poset (Z, |)?
Question: Is the “inclusion” relation on P(S) of S a partial ordering, poset (P(S), )?
Question: Are (Z,=) , (Z,≠) and (Z, |)? 47
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.

48
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).
In poset (Z+, |), are the integers 3 and 9 comparable? Are 2 and 3 comparable?
 We can note that Z+={ 1, 2, 3, …} and R={… , (3,3), (3, 9), …}. Thus, not all
elements in Z+ can be in R.
9
 The integers 3 and 9 are comparable, because 3 | 9. (i.e., = 3)
3
 The integers 2 and 3 are incomparable, because 2|3 and 3|2. (i.e., 32=1.5, 2
3
= 0.66 )

49
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 2 and 3.

50
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: Partial order

 The set {3, 6, 9} has a least element: {3}. Totally


Ordered
Well-ordered
 The set of natural numbers has a least element: {0}.

 The set of real numbers do not have a least element.


 The set of negative integers do not have a least element.

 The set of rational numbers do not have a least element.


 (If p/q∈Q+ , we can find p/(q+1) ∈ Q+ and it is less than p/q)
51
Functions
(In Book: Chapter 2-sec 2.3)

52
Relations and Function
 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.
 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.

 When we assign to each element of a set a particular element of a second set.

 Which of these figures is a function?

53
Functions

• Example of a function :
• 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.

Amal A
Rawan B
Maha C
Sara D
F
Safia
S G

54
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
55
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

56
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
57
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.

58
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 59
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} 60
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, …}
61
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.

62
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


63
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.


64
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.
65
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.

66
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 x 2 = -1.

Example :

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

integers to itself is onto.


67
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.
68
Some examples

69
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?

70
Functions-Questions

Q3. Suppose f: R+ → R+,


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

Q4. Suppose f: R → R+,


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

71
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?

72
Functions-Questions

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


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

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. not function?
Is f one-to-one?no
Is f onto?yes
Is f bijective?no

73
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
74
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?
75
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
76
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 fog
(f o g)(a) = f(g(a)) = f(b) = 2, a 1
a
b g f 2
(f o g)(b) = f(g(b)) = f(c) = 1, and b
c 3
(f o g)(c) = f(g(c)) = f(a) = 3. c

Note that g o f is not defined, because the range of f is not subset of the
domain of g. gof
a 1 a
b f 2 g b
c 3 c

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)?
77
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.

78
Functions -Examples

Example 19:

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

79
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)

80
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 ?

81

You might also like