You are on page 1of 117

DISCRETE STRUCTURES FOR

COMPUTER SCIENCE

BITS Pilani
Pilani|Dubai|Goa|Hyderabad
BITS Pilani
Pilani|Dubai|Goa|Hyderabad

M3: Sets, Function and Relations


BITS Pilani
Pilani|Dubai|Goa|Hyderabad

Contact Session 6
Sets, Operation on Sets And Functions
Sets
A set is well defined collection or group of objects or elements or members.
Example X is a set containing three elements a, b and c.
X ={a,b,c} a,b,c∈ X ; d is not an element of X: d X.
The set-builder notation
O={ x | (xZ)  (x=2k) for some kZ}
reads: O is the set that contains all x such that x is an integer and x is even
• A set is defined in intension when you give its set-builder notation
O={ x | (xZ)  (0x8)  (x=2k) for some k  Z }
• A set is defined in extension when you enumerate all the elements:
O={0,2,4,6,8}
Use set builder notation to give a description of each of these sets.
a) {0, 3, 6, 9, 12} ={x | x=3k and k=0,1,2,3,4}
b) {−3,−2,−1, 0, 1, 2, 3} = { x | -3 <= x <= 3}
c) {m, n, o, p}

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Sets
Two sets, A and B, are equal is they contain the same elements. We write A=B.
Example:
{2,3,5,7}={3,2,7,5}, because a set is unordered
Also, {2,3,5,7}={2,2,3,5,3,7} because a set contains unique elements
However, {2,3,5,7} {2,3}
Determine whether each of these pairs of sets are equal.
a) {1, 3, 3, 3, 5, 5, 5, 5, 5}, {5, 3, 1}
b) {{1}}, {1, {1}}
c) ∅, {∅}
A set that has no elements is called the empty set or null set and is denoted 
A set that has one element is called a singleton set.
For example: {a}, with brackets, is a singleton set a, without brackets, is an element of the set {a}
Note the subtlety in   {}
The left-hand side is the empty set
The right hand-side is a singleton set, and a set containing a set

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Example
Rosen , Section 2.1: 1
List the members of these sets.
a) {x | x is a real number such that x2 = 1}
b) {x | x is a positive integer less than 12}
c) {x | x is the square of an integer and x < 100}
d) {x | x is an integer such that x2 = 2}

Solution:
a) {1,-1}
b) {1,2,3,4,5,6,7,8,9,10,11}
c) {0, 1, 4, 9, 16, 25, 36, 49, 64, 81}
d)  (√ 2 is not integer )
6
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Sets
Subsets
Definition: The set A is a subset of the set B, denoted
A  B, iff x [x  A  x  B]

Example X ={a,b,c}, Y = {a,b} and Z = {a,c} . Y and Z are subsets of X.


Properties of Subsets
(i) If A ⊆ B and B ⊆ C , A ⊆ C .
(ii) For any set A, A ⊆ A .i.e; A Set is a Subset of itself
Proper subset
A set A that is a subset of a set B is called a proper subset if A  B.
That is there is an element xB such that xA
We write: A  B, A  B
Sets can be elements of other sets
Examples S1 = {,{a},{b},{a,b},c}
S2={{1},{2,4,8},{3},{6},4,5,6}
7

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Example
For each of these pairs of sets, determine whether the first is a
subset of the second, the second is a subset of the first, or
neither is a subset of the other.

a) the set of airline flights from NewYork to New Delhi, the set of
nonstop airline flights from New York to New Delhi
b) the set of people who speak English, the set of people who
speak Chinese
c) the set of flying squirrels, the set of living creatures that can fly

8
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
Rosen , Section 2.1: 6
• Suppose that A = {2, 4, 6}, B = {2, 6}, C = {4, 6},
and D = {4, 6, 8}.
• Determine which of these sets are subsets of
which other of these sets.

9
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen , Section 2.1: 18
18. Find two sets A and B such that
A ∈ B and A ⊆ B.

B={ a, φ}
A= φ  A ∈ B
Also φ ⊆ B  A ⊆ B

10
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
Rosen , Section 2.1: 9,10,11
Determine whether each of these statements is true or false.
1) 0 ∈ ∅ F 2) ∅ ∈ {0} F
3) {0} ⊂ ∅F 4) ∅ ⊂ {0} T
5) {0} ∈ {0} F 6) {0} ⊂ {0} T
7) {∅} ⊆ {∅} 8) ∅ ∈ {∅}
9) ∅ ∈ {∅, {∅}} 10) {∅} ∈ {∅}
11) {∅} ∈ {{∅}} 12) {∅} ⊂ {∅, {∅}}
13 ) {{∅}} ⊂ {∅, {∅}} 14) {{∅}} ⊂ {{∅}, {∅}}
15) {x} ⊆ {x}
16) {x} ∈ {x}
17) {x} ∈ {{x}}
18) ∅ ⊆ {x}
19 ) ∅ ∈ {x}
20) x ∈ {x} ) T (in fact x is the only element)
11
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solutions
1) 0∈∅ F
2) ∅ ∈ {0} F (the only element of { 0} is 0 , not a set)
3) {0} ⊂ ∅ F
4) ∅ ⊂ {0} T (the empty set is a subset of every set)
5) {0} ∈ {0} F (the only element of { 0} is 0, not a set)
6) {0} ⊂ {0} T (every set is a subset of itself)
7) {∅} ⊆ {∅} T (every set is a subset of itself)
8) ∅ ∈ {∅ } T
9) ∅ ∈ {∅, {∅}} T
10) {∅ } ∈ { ∅ } F
11) {∅} ∈ {{∅}} T
12) {∅} ⊂ {∅, {∅}} T
13 ) {{ ∅}} ⊂ {∅, { ∅}} T
14) {{∅}} ⊂ {{∅}, {∅}} T
15) {x} ⊆ {x} T (every set is a subset of itself)
16) {x} ∈ {x} F (the only element of { x} is a letter, not a set)
17) {x} ∈ {{x}} T
18) ∅ ⊆ {x} T (the empty set is a subset of every set)
19 ) ∅ ∈ {x} F (the only element of { x} is a letter, not a set)
20) x ∈ {x} T (in fact x is the only element)

12
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Sets
• Definition: If there are exactly n distinct elements in a set S, with n
a nonnegative integer, we say that:
– S is a finite set, and
– The cardinality of S is n. Notation: |S| = n.
• Definition: A set that is not finite is said to be infinite

• Examples
– Let B = {x | (x100)  (x is prime)}, the cardinality of B is |B|=25
because there are 25 primes less than or equal to 100.
– The cardinality of the empty set is ||=0
– The sets N, Z, Q, R are all infinite

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Example
Rosen , Section 2.1: 19,20

What is the cardinality of each of these sets?


a) {a}
b) {{a}}
c) {a, {a}}
d) {a, {a}, {a, {a}}}

20. What is the cardinality of each of these sets?


a) ∅ b) {∅} c) {∅,{∅}} d) {∅,{∅},{∅,{∅}}}
14
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Power Set

• Definition: The power set of a set S, denoted P(S), is the set of all
subsets of S.
– Examples
• Let A={a,b,c}, P(A)={,{a},{b},{c},{a,b},{b,c},{a,c},{a,b,c}}
• Let A={{a,b},c}, P(A)={,{{a,b}},{c},{{a,b},c}}
– Note: the empty set  and the set itself are always elements
of the power set.
• The power set is a fundamental combinatorial object useful when
considering all possible combinations of elements of a set
• Fact: Let S be a set such that |S|=n, then
|P(S)| = 2n

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Example
1.Find the power set of each of these sets, where a and b are distinct elements.
a) {a}
b) {a, b}
c) {∅, {∅}}
2. How many elements does each of these sets have where a and b are distinct
elements?
a) P({a, b, {a, b}})
b) P({∅, a, {a}, {{a}}})
c) P(P(∅))
3. Determine whether each of these sets is the power set of a set, where a and b are
distinct elements.
d) ∅
e) {∅, {a}}
c) {∅, {a}, {∅, a}}
d) {∅, {a}, {b}, {a, b}} 16
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Ordered n-tuple
• Sometimes we need to consider ordered collections
of objects
• Definition: The ordered n-tuple (a1,a2,…,an) is the
ordered collection with the element ai being the i-th
element for i=1,2,…,n
• Two ordered n-tuples (a1,a2,…,an) and (b1,b2,…,bn) are
equal iff for every i=1,2,…,n we have ai=bi (a1,a2,…,an)
• A 2-tuple (n=2) is called an ordered pair
• (2,3) is an ordered 2-tuple (pair)
• (3,8,5) is an ordered 3-tuple (triple) 17
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Cartesian Product
• Definition: Let A and B be two sets. The Cartesian product of
A and B, denoted AxB, is the set of all ordered pairs (a,b)
where aA and bB
AxB = { (a,b) | (aA)  (b  B) }
• The Cartesian product is also known as the cross product
• Definition: A subset of a Cartesian product, R  AxB is called a
relation.
• Note: AxB  BxA unless A= or B= or A=B.
• Cartesian Products can be generalized for any n-tuple
– Definition: The Cartesian product of n sets, A1,A2, …, An, denoted
A1A2… An, is
A1A2… An ={ (a1,a2,…,an) | ai  Ai for i=1,2,…,n}
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
Find A2 if
a) A = {0, 1, 3}.
A2= {(0,0)(0,1),(0,3),(1,0),(1,1),(1,3),(3,0),(3,1),(3,3)}
b) A = {1, 2, a, b}. HW
Find A3 if
c) A = {a}. A^2 ={(a,a)}. A^3 = A^2 x A={((a,a),a)}
d) A = {0, a}.

19
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen , Section 2.1: 28,30
28. What is the Cartesian product A × B, where A
is the set of courses offered by the mathematics
department at a university and B is the set of
mathematics professors at this university?
Give an example of how this Cartesian product
can be used.
AxB ={ (ci, pj) | ci is a course offered and pj is a
professor in the dept}

20
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
• 30. Suppose that A × B = ∅, where A and B are
sets. What can you conclude?
• A × B = ∅  A = ∅ or B= ∅

21
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Venn Diagram
• A set can be represented graphically using a Venn
Diagram.We use a rectangle to represent the universal set U
and circles to represent subsets of U.

U x y B
A
z

a
C

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Example
Rosen , Section 2.1:13,14,15,16
13.Use a Venn diagram to illustrate the set of all months of the year whose
names do not contain the letter R in the set of all months of the year.

14: Use a Venn diagram to illustrate the relationship A ⊆ B and B ⊆ C.


15: Use a Venn diagram to illustrate the relationships A ⊂ B and B ⊂ C.
16 Use a Venn diagram to illustrate the relationships A ⊂ B and A ⊂ C.

23
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
Rosen , Section 2.1:13
Use a Venn diagram to illustrate the set of all months of the
year whose names do not contain the letter R in the set of all
months of the year.

24
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
Rosen , Section 2.1: 14,15,16
14: Use a Venn diagram to illustrate the relationship A ⊆ B and B ⊆ C.
15: Use a Venn diagram to illustrate the relationships A ⊂ B and B ⊂ C.
16 Use a Venn diagram to illustrate the relationships A ⊂ B and A ⊂ C.

x
y

A ⊂ B and B ⊂ C
A ⊂ B and A ⊂ C
A ⊆ B and B ⊆ C.

y
x

25
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Set Operations
• Arithmetic operators (+,-,  ,) can be used on
pairs of numbers to give us new numbers
• Similarly, set operators exist and act on two
sets to give us new sets
– Union
– Intersection
– Set difference
– Set complement
– Generalized union
– Generalized intersection

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Set Operators: Union
• Definition: The union of two sets A and B is the set that
contains all elements in A, B, r both. We write:
AB = { x | (a  A)  (b  B) }
The union of the sets {1, 3, 5} and {1, 2, 3}
{1, 3, 5} ∪ {1, 2, 3} = {1, 2, 3, 5}.

U
A B

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Set Operators: Intersection
• Definition: The intersection of two sets A and B is the set that
contains all elements that are element of both A and B. We write:
A  B = { x | (a  A)  (b  B) }
The intersection of the sets {1, 3, 5} and {1, 2, 3}
{1, 3, 5} ∩ {1, 2, 3} = {1, 3}.

U
A B

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Disjoint Sets
• Definition: Two sets are said to be disjoint if their
intersection is the empty set: A  B = 
Let A = {1, 3, 5, 7, 9} and B = {2, 4, 6, 8, 10}.
Because A ∩ B = ∅, A and B are disjoint.

U
A B

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Set Difference
• Definition: The difference of two sets A and B, denoted A\B
or A−B, is the set containing those elements that are in A
but not in B
The difference of {1, 3, 5} and {1, 2, 3}: {1, 3, 5} − {1, 2, 3} = {5}.
Note: The difference of {1, 2,3} and {1,3,5}: {1, 2, 3} - {1, 3, 5} = {2}.

U
A B

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Symmetrical Difference
• Symmetrical Difference
– The symmetrical difference of A and B, denoted by
A⊕ B , is the set containing those elements in
either A or B, but not in both A and B.
• Example
– Suppose A = {a,b,c} and B = {c, d}. A⊕ B = {a,b,d}.

31
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen , Section 2.2: 39

39. What can you say about the sets A and B


if A ⊕ B = A?

Solution:
We can conclude that B = 0. To see this, suppose that B contains some
element b. If b  A, then b is excluded from A ⊕ B,
so A ⊕ B cannot equal A.
On the other hand, if b  A, then b must be in A ⊕ B,
so again A ⊕ B cannot equal A.
Thus in either case, A ⊕ B  A.
We conclude that B cannot have any elements.

32
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Set Complement
• Definition: The complement of a set A,
denoted A , consists of all elements not in A.
That is the difference of the universal set and
U: U\A
A= AC = {x | x  A }

U A
A

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Example
• Let A be the set of positive integers greater
than 10 (with universal set the set of all
positive integers).
• Then A = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.

34
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Set Complement: Absolute & Relative
• Given the Universe U, and A,B  U.
• The (absolute) complement of A is A=U\A
• The (relative) complement of A in B is B\A

U U
A A B
A

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Rosen , Section 2.2:4
4. Let A = {a, b, c, d, e} and B = {a, b, c, d, e, f, g, h}.
Find
a) A ∪ B.
b) A ∩ B.
c) A − B.
d) B − A.
Let A = {0, 2, 4, 6, 8, 10}, B = {0, 1, 2, 3, 4, 5, 6}, and
C = {4, 5, 6, 7, 8, 9, 10}. Find
a) A ∩ B ∩ C. b) A ∪ B ∪ C.
c) (A ∪ B) ∩ C. d) (A ∩ B) ∪ C.

36
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
27.Draw the Venn diagrams for each of these combinations
of the sets A, B, and C.
a) A ∩ (B − C) A B
A ∩(B-C)
b) b) (A ∩ B) ∪ (A ∩ C)
c) (A ∩ B) ∪ (A ∩ C) C
28. Draw the Venn diagrams for each of these combinations
of the sets A, B, C, and D.
c) (A ∩ B) ∪ (C ∩ D)
d) A ∪ B ∪ C ∪ D
c) A − (B ∩ C ∩ D)

37
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Set Identities

38
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen , Section 2.2:30
30.Can you conclude that A = B
if A, B, and C are sets such that
a) A ∪ C = B ∪ C? b) A ∩ C = B ∩ C?
c) A ∪ C = B ∪ C and A ∩ C = B ∩ C?

39
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Union Rule for Sets
• Union Rule for Sets
n( A∪B) = n( A) + n(B) − n( A∩B)
• where n( X ) is the number of elements in set X.
• Union Rule for Disjoint Sets
If A and B are disjoint sets,
n( A∪B) = n( A) + n(B) .

40
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Proving Equivalence
• Finally to show that two sets are equal, it is sufficient
to show independently (much like a biconditional)
that
– A  B and
– BA
• Logically speaking, you must show the following
quantified statements:
(x (xA  xB))  (x (xB  xA))

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Proving Set Equivalences
• Recall that to prove such identity, we must show
that:
1. The left-hand side is a subset of the right-hand side
2. The right-hand side is a subset of the left-hand side
3. Then conclude that the two sides are thus equal

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Proving Set Equivalences: Example A (1)

• Let
– A={x|x is even}
– B={x|x is a multiple of 3}
– C={x|x is a multiple of 6}
• Show that AB=C

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Proving Set Equivalences: Example A (2)

• AB  C:  x  AB
Þ x is a multiple of 2 and x is a multiple of 3
Þ we can write x=2.3.k for some integer k
Þ x=6k for some integer k  x is a multiple of 6
ÞxC
• C AB:  x C
Þ x is a multiple of 6  x=6k for some integer k
Þ x=2(3k)=3(2k)  x is a multiple of 2 and of 3
Þ x  AB
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Proving Set Equivalences

An alternative prove is to use membership


tables where an entry is
1 if a chosen (but fixed) element is in the set
0 otherwise
Example{Rosen Section 2.2:17}:
Show that
ABC=ABC

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Proving Set Equivalences
Solution:[Rosen, Section2.2:17]
A B C ABC ABC A B C ABC
0 0 0 0 1 1 1 1 1
0 0 1 0 1 1 1 0 1
0 1 0 0 1 1 0 1 1
0 1 1 0 1 1 0 0 1
1 0 0 0 1 0 1 1 1
1 0 1 0 1 0 1 0 1
1 1 0 0 1 0 0 1 1
1 1 1 1 0 0 0 0 0

• 1 under a set indicates that “an element is in the set”


• If the columns are equivalent, we can conclude that indeed
the two sets are equal

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Generalizing Set Operations: Union and Intersection

• In the previous example, we showed De


Morgan’s Law generalized to unions involving
3 sets
• In fact, De Morgan’s Laws hold for any finite
set of sets
• Moreover, we can generalize set operations
union and intersection in a straightforward
manner to any finite number of sets

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Generalized Union
• Definition: The union of a collection of sets is
the set that contains those elements that are
members of at least one set in the collection

A =A
n

i 1  A2  …  An
i=1

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Generalized Intersection
• Definition: The intersection of a collection of
sets is the set that contains those elements
that are members of every set in the collection
n

A =A
i=1
i 1  A2 … An

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Rosen , Section 2.2:51
51. Find U∞ i=1 Ai and  ∞ i=1 Ai
if for every positive integer i,
a) Ai = {−i, −i + 1,..., −1, 0, 1,...,i − 1, i}.
b) Ai = {−i, i}.
c) Ai = [−i, i], that is, the set of real numbers x
with −i ≤ x ≤ i.
d) Ai = [i,∞), that is, the set of real numbers x
with x ≥ i
50
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
a) As i increases, the sets get larger: Ai  A2  A3 · · ·. All the sets are subsets of the set of integers,
and every integer is included eventually, so U∞ i=1 Ai = Z. Because Ai is a subset of each of the others,
 ∞ i=1 Ai = Ai = {-1, 0, 1}.

b) All the sets are subsets of the set of integers, and every nonzero integer is in exactly one of the sets, so
U∞ i=1 Ai = Z - {O}. Each pair of these sets are disjoint, so no element is common to all of the sets. Therefore
Ç ∞
i=1 Ai i = .

c) This is similar to part (a), the only difference being that here we are working with real numbers.
Therefore U∞ i=1 Ai = R (the set of all real numbers), and  ∞ i=1 Ai = A1 = [-1, 1] (the interval of all real numbers
between -1 and 1, inclusive).

d) This time the sets are getting smaller as i increases: · · ·  A3  A2  A1 . Because A1 includes all
the others, U∞ i=1 Ai = A1 = [1, ∞) (all real numbers greater than or equal to 1). Every number eventually
gets excluded as i increases, so  ∞ i=1 A = . Notice that ∞ is not a real number, so we cannot write
 ∞ i=1 Ai = {∞}

51
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Successor of a Set
The successor of the set A is the set A ∪ {A}.

59. Find the successors of the following sets.


a) {1, 2, 3}
b) ∅
c) {∅}
d) {∅,{∅}}
Solution
We simply adjoin the set itself to the list of its elements.
b) {1,2,3,{l,2,3}}
b) {∅}
c) {∅,{∅}}
d) {∅,{∅},{∅,{∅}}}
52
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Pilani|Dubai|Goa|Hyderabad

Functions
Definition of Functions
Let A and B be sets. A function f from A to 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 element a of A. If f is a
function from A to B, we write f : A→ B .
R={(a1,b1), (a2,b2), (a3,b4),
(a4,b4)} subset of AxB

Remark: Functions are sometimes also called mappings or transformations.

54

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Graphical Representations
• Functions can be represented graphically in
several ways:

f A B
• •
f • •
• • • y
a b •


• x
A
B Graph Plot
Like Venn diagrams
55

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Domain, Codomain and Range
• If f is a function from A to B, we say that
• A is the domain of f
• B is the codomain 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 of f is the set of all images of elements of A.

• Remark: Let S be a subset of A. The image of S is the set of all the


images of the elements in S and is denoted by f (S ).
56
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
What are the domain, codomain, and range of the function that
assigns grades to students Ravi
Sham
Anil
Dilip
Solution: Kevin
Let G be the function that assigns a grade to a student in our discrete
mathematics class.
Note that G(Ravi) = A, for instance.
The domain of G is the set {Ravi,Sham,Anil,Dilip,Kevin}, and
the codomain is the set {A,B,C,D, F}.
The range of G is the set {A,B,C, F}, because each grade except D is
assigned to some student. 57
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
Let f be the function that assigns the last two bits of a bit string
of length 2 or greater to that string.
Solution:
For example, f (11010) = 10.
Then, the domain of f is the set of all bit strings of length 2 or
greater,
and both the codomain and range are the set {00, 01, 10, 11}.

58
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen, Section2.3: 4
4) Find the domain and range of these functions. Note that in
each case, to find the domain, determine the set of elements
assigned values by the function.
a) the function that assigns to each nonnegative integer its last
digit
b) the function that assigns the next largest integer to a positive
integer
c) the function that assigns to a bit string the number of one bits
in the string
d) the function that assigns to a bit string the number of bits in
the string

59
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
a) the function that assigns to each nonnegative integer its last digit
Clearly the Domain is Zero and all possible positive Integers , The Range set
include last digit [Ones place] which can hold nos {0,1,2,3,4,5,6,7,8,9}.
b) the function that assigns the next largest integer to a positive integer
Clearly the Domain is all possible positive Integers , The Range set includes all
Natural numbers greater than 1.
c) the function that assigns to a bit string the number of one bits in the string
Clearly the Domain is the set of all bit strings. The Range is Z+U{0}; the function
evaluated at a string with n l's
d) the function that assigns to a bit string the number of bits in the string
Clearly the Domain is the set of all bit strings. The Range is Z+; the function evaluated
at a string with n - l's and m - 0's

60
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen, Section2.3: 5
5. Find the domain and range of these functions. Note that in each
case, to find the domain, determine the set of elements assigned
values by the function.
a) the function that assigns to each bit string the number of ones
in the string minus the number of zeros in the string
b) the function that assigns to each bit string twice the number of
zeros in that string
c) the function that assigns the number of bits left over when a
bit string is split into bytes (which are blocks of 8 bits)
d) the function that assigns to each positive integer the largest
perfect square not exceeding this integer

61
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
In each case we want to find the domain (the set on which the function operates, which is implicitly stated in
the problem) and the range (the set of possible output values).
a) the function that assigns to each bit string the number of ones in the string minus the number of zeros in
the string
Clearly the domain is the set of all bit strings. The range is Z; the function evaluated at a string with n l's and no
O's is n, and the function evaluated at a string with n O's and no l's is -n.
b) the function that assigns to each bit string twice the number of zeros in that string
Again the domain is clearly the set of all bit strings. Since there can be any natural number of O's in a bit string,
the value of the function can be 0, 2, 4, .... Therefore the range is the set of even natural numbers.
c) the function that assigns the number of bits left over when a bit string is split into bytes (which are blocks
of 8 bits)
Again the domain is the set of all bit strings. Since the number of leftover bits can be any whole number
from 0 to 7 (if it were more, then we could form another byte),
the range is {O, 1, 2, 3, 4, 5, 6, 7}.
d) the function that assigns to each positive integer the largest perfect square not exceeding this integer
As the problem states, the domain is the set of positive integers. Only perfect squares can be function values,
and clearly every positive perfect square is possible. Therefore the range is {l, 4, 9, 16, ... }.

62
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real-valued Functions
A function is said to be real-valued if all its
values are real numbers.
Example
f (x) = x2 for all x ∈ R

63
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Addition and Multiplication of Real-valued function

Let f and g be functions from A to R.


Then the sum f + g and the product f ⋅ g of f and g are defined
as follows:
( f + g)(x) = f (x)+ g(x) and
( f ⋅ g)(x) = f (x)⋅ g(x)
Example
Let f (x) = x +1and g(x) = x2 .
( f + g)(x) = (x +1)+ (x2 )= x2 + x +1 and
( f ⋅ g)(x) = (x +1)⋅ (x2 )= x3 + x2
PROBLEM:

• Let f1 and f2 be functions from R to R such that f1(x) = x2 and


f2(x) = x − x2. What are the functions f1 + f2 and f1f2? 64
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Function Composition

• For functions g:AB and f:BC, there is a special


operator called compose (“○”).
– It composes (i.e., creates) a new function out of f,g by
applying f to the result of g.
(f○g):AC, where (f○g)(a) = f(g(a)).
– Note g(a)B, so f(g(a)) is defined and C.
– The range of g must be a subset of f’s domain!!
– Note that ○ (like Cartesian , but unlike +,,) is non-
commuting. (In general, f○g  g○f.)

65

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Function Composition

66

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Example
Let g be the function from the set {a, b, c} to itself such that g(a) = b, g(b) = c,
and g(c) = a.
Let f be the function from the set {a, b, c} to the set {1, 2, 3} such that f (a) = 3,
f (b) = 2, and f (c) = 1.
What is the composition of f and g, and what is the composition of g and f ?

Solution:
The composition f ◦ g is defined by
(f ◦ g)(a) = f (g(a)) = f (b) = 2,
(f ◦ g) (b) = f (g(b)) = f (c) = 1, and
(f ◦ g)(c) = f (g(c)) = f (a) = 3.
Note that g ◦ f is not defined, because the range of f is not a subset of the
domain of g.
67
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
Let f and g be the functions from the set of integers to the set of
integers defined by f (x) = 2x + 3 and g(x) = 3x + 2. What is the
composition of f and g? What is the composition of g and f ?

Solution:
Both the compositions f ◦ g and g ◦ f are defined. Moreover,
(f ◦ g)(x) = f (g(x)) = f (3x + 2) = 2(3x + 2) + 3 = 6x + 7
and
(g ◦ f )(x) = g(f (x)) = g(2x + 3) = 3(2x + 3) + 2 = 6x + 11.

68
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Images of Sets under Functions
• Given f:AB, and SA,
• The image of S under f is simply the set of all
images (under f) of the elements of S.
f(S) : {f(s) | sS}
: {b |  sS: f(s)=b}.
• Note the range of f can be defined as simply
the image (under f) of f’s domain!

69

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Example
Let A = {a, b, c, d, e} and B = {1, 2, 3, 4} with
f (a) = 2,
f (b) = 1,
f (c) = 4,
f (d) = 1, and
f (e) = 1.
The image of the subset S = {b, c, d} is the set f
(S) = {1, 4}.
70
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
One-to-One Functions
• A function is one-to-one (1-1), or injective, or an
injection, iff every element of its range has only one
pre-image.
• Only one element of the domain is mapped to any
given one element of the range.
– Domain & range have same cardinality.
– What about codomain?

71

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Example
Suppose that each worker in a group of
employees is assigned a job from a set of
possible jobs, each to be done by a single
worker.
To see this, note that if x and y are two different
workers, then f (x) = f (y) because the two
workers x and y must be assigned different
jobs.
In this situation, the function f that assigns a job
to each worker is one-to-one. 72
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
One-to-One Illustration

• Graph representations of functions that are


(or not) one-to-one:
• • • •
• • • • •
• • • •
• • • •
• • •
• • • •
• •

Not one-to-one Not even a
One-to-one function!

73

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Sufficient Conditions for 1-1ness
• Definitions (for functions f over numbers):
– f is strictly (or monotonically) increasing iff x>y
 f(x)>f(y) for all x,y in domain;
– f is strictly (or monotonically) decreasing iff x>y
 f(x)<f(y) for all x,y in domain;
• If f is either strictly increasing or strictly
decreasing,(indicates a strict inequality)
then f is one-to-one.
– e.g. f(x)=x3
74

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Example
Determine whether the function f (x) = x2 from the set
of integers to the set of integers is one-to-one.
Solution:
The function f (x) = x2 is not one-to-one because, for
instance, f (1) = f (−1) = 1,but 1 = −1.

Note that the function f (x) = x2 with its domain


restricted to Z+ is one-to-one.

75
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen, Section2.3:10
10. Determine whether each of these functions from
{a, b, c, d} to itself is one-to-one.
a) f (a) = b, f (b) = a, f (c) = c, f (d) = d

b) f (a) = b, f (b) = b, f (c) = d, f (d) = c

c) f (a) = d, f (b) = b, f (c) = c, f (d) = d

76
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen, Section2.3: 12
12. Determine whether each of these functions
from Z to Z is one-to-one.
a) f (n) = n − 1
b) f (n) = n2 + 1
c) f (n) = n3
d) f (n) = n/2 = largest integer greater than n/2
F(2)=ceil(1)=1; f(1)=ceil(0.5)=1

77
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
f (n) = n − 1
• Let f(n1)=f(n2)  n1-1=n2-1  n1=n2
• F is 1-1

• b) f (n) = n2 + 1
• Let f(x)=f(y)  x^2 + 1 =y^2 +1  x^2 = y^2
• x=1, y=-1. x!=y but x^2=y^2
• F is not 1-1

78
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
a) f (n) = n − 1
This function is one to one. Since n - 1 is always decremental mapping
and is always one to one mapping.

b) f (n) = n2 + 1
This function is not one to one. Since n 2 always map to positive
numbers for both negative and positive [Eg: (-2) 2 and 2 2 map to 4]
so n2 + 1 is not one to one mapping
c) f (n) = n3
This function is one to one. Since n3 is incremental
d) f (n) = n/2
This function is one to one. If we want to obtain the value n, then we
simply need to start with 2n, since f(2n) = 2n/2 =  n  = n for all n E Z.
79
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen, Section2.3:17
17. Consider these functions from the set of teachers in a school. Under what conditions is the
function one-to-one if it assigns to a teacher his or her
a) office.
b) assigned bus to chaperone in a group of buses taking students on a field trip.
c) salary.
d) social security number

80
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
a) This may be one-to-one (if there are no shared offices) or not (if there are shared
offices).

b) Again, this depends on the policy of the school. Assuming that no bus gets more
than one teacher chaperone, this function will be one-to-one.

c) This is most likely not one-to-one, because two teachers might have the same
salary. On the other hand, it may happen that everyone's salary is different, in which
case it is one-to-one.

d) This is clearly a one-to-one function, because social security numbers are unique--
no two people can have the same social security number

81
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen, Section2.3:27
27.
a) Prove that a strictly decreasing function from R to itself is one-to-one.
b) Give an example of a decreasing function from R to itself that is not one-to-one.

Solution:
c) Let f be the given strictly decreasing function from R to itself. We need to show that
f(a) = f(b) implies a= b for all a, b  R. We give an indirect proof by proving the
contrapositive: if a  b, then f(a)  f(b). There are two cases. Suppose a < b; then
because f is strictly decreasing, it follows that f(a) > f(b). Similarly, if a> b, then f(a)
< f(b). Thus in either case, f(a)  f(b).
d) We need to make the function decreasing, but not strictly decreasing, so, for
example, we could take the trivial function f ( x) = 17. If we want the range to be all
of R, we could define f in parts this way: f(x) = -x - l for x < -1; f(x) = 0 for -1<= x<=1;
and f(x) = -x+ 1 for x > 1.

82
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen, Section2.3:26
26.
a) Prove that a strictly increasing function from R to itself is one-
to-one.
b) Give an example of an increasing function from R to itself that
is not one-to-one.
• b) A={1,2,3} f: A A as f(1) = 1, f(2)=1, f(3)=2
• f is increasing function.
• But as f(1)=f(2), f is NOT 1-1.

83
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Onto (Surjective) Functions
A function f:AB is onto or surjective or a surjection
iff its range is equal to its codomain (bB, aA:
f(a)=b).
An onto function maps the set A onto (over, covering)
the entirety of the set B, not just over a piece of it.
e.g., for domain & codomain R,
x3 is onto,
whereas x2 isn’t. (Why not?)

84

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Illustration of Onto
• Some functions that are or are not onto their
codomains:


• • • • • • • •
• • • • • • • •
• • • •
• • • •
• • • • • •
• • • •
Onto Not Onto Both 1-1 1-1 but
(but not 1-1) (or 1-1) and onto not onto
85

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Example
Let f be the function from {a, b, c, d} to {1, 2, 3} defined
by f (a) = 3, f (b) = 2, f (c) = 1,and f (d) = 3. Is f an onto
function?

Solution:
Because all three elements of the codomain are images
of elements in the domain, we see that f is onto.

Note that if the codomain were {1, 2, 3, 4},then f would


not be onto.
86
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen, Section2.3: 15
15. Determine whether the function f : Z × Z → Z
is onto if
a) f (m, n) = m + n.
b) f (m, n) = m2 + n2.
c) f (m, n) = m.
d) f (m, n) = |n|.
e) f (m, n) = m − n. X =(x+1)-1 = m – n
f(x+1, 1) =x
87
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
An onto function is one whose range is the entire codomain. Thus we must
determine whether we can write every integer in the form given by the rule
for f in each case.
a) Given any integer n, we have f(O, n) = n, so the function is onto.
b) Clearly the range contains no negative integers, so the function is not
onto.
c) Given any integer m, we have f(m, 25) = m, so the function is onto. (We
could have used any constant in place of 25 in this argument.)

d) Clearly the range contains no negative integers, so the function is not


onto.
e) Given any integer m, we have f(m, 0) = m, so the function is onto.

88
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen, Section2.3:18
18 Consider these functions from the set of students in a discrete
mathematics class. Specify a codomain for each of the functions. Under what
conditions is each of these functions with the codomain you specified onto? if
it assigns to a student his or her
a) mobile phone number.
b) student identification number.
c) final grade in the class.
d) home town.

89
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Bijections
• A function f is a one-to-one correspondence, or a
bijection, or reversible, or invertible,
iff it is both one-to-one and onto.
Example:
Let f be the function from {a, b, c, d} to {1, 2, 3, 4} with f (a) = 4, f
(b) = 2, f (c) = 1, and f (d) = 3. Is f a bijection?
Solution:
The function f is one-to-one and onto. It is one-to-one because no two
values in the domain are assigned the same function value.
It is onto because all four elements of the codomain are images of
elements in the domain.
Hence, f is a bijection.
90

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Rosen, Section2.3: 23
Determine whether each of these functions is a
bijection from R to R.
a) f (x) = 2x + 1
b) f (x) = x2 + 1
c) f (x) = x3
d) f (x) = (x2 + 1)/(x2 + 2)

91
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
a) One way to determine whether a function is a bijection is to try to construct its
inverse. This function is a bijection, since its inverse (obtained by solving y = 2x + 1
for x) is the function g(y) = (y - 1) /2. Alternatively, we can argue directly. To show
that the function is one-to-one, note that if 2x + 1 = 2x' + 1, then x = x'. To show
that the function is onto, note that 2( (y - 1) /2) + 1 = y, so every number is in the
range.
b) This function is not a bijection, since its range is the set of real numbers greater
than or equal to 1 (which is sometimes written [1, ∞)), not all of R. (It is not
injective either.)
c) This function is a bijection, since it has an inverse function, namely the function
f(y) = y1/3 (obtained by solving y = x 3 for x).
d) This function is not a bijection. It is easy to see that it is not injective, since x and -x
have the same image, for all real numbers x. A little work shows that the range is
only { y I 0.5 <= y < 1} = [0.5, 1)

92
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Inverse of a Function
• For bijections f:AB, there exists an inverse
of f, written f 1:BA, which is the unique
function such that:

93

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Example
Let f be the function from {a, b, c} to {1, 2, 3} such that f (a) = 2, f (b)
= 3, and f (c) = 1.
Is f invertible, and if it is, what is its inverse?

Solution:
The function f is invertible because it is a one-to-one
correspondence.
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.

94
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
Let f : Z → Z be such that f (x) = x + 1. Is f invertible, and if it is, what
is its inverse?

Solution:
The function f has an inverse because it is a one-to-one
correspondence.
To reverse the correspondence, suppose that y is the image of x, so
that y = x + 1. Then x = y − 1. This means that y − 1 is the unique
element of Z that is sent to y by f . Consequently, f−1(y) = y − 1.

95
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen, Section2.3: 42
42. Let f be the function from R to R defined by
f (x) = x2. Find
a) f−1({1}).
b) f−1({x | 0 < x < 1}).
c) f−1({x | x > 4}).

96
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
a) We want to find the set of all numbers whose floor is 0. Since all numbers
from 0 to 1 (including 0 but not 1) round down to 0,
we conclude that g-1 ( {0}) = { x I 0 <=x < 1} = [0, 1).

b) This is similar to part (a). All numbers from -1 to 2 (including -1 but not 2)
round down to -1, 0, or l;
we conclude that g-1 ({-1,0, 1}) = {x I -1<=x<2} =[-1,2)

c) Since g(x) is always an integer, there are no values of x such that g(x) is
strictly between 0 and 1. Thus the inverse image in this case is the empty
set.

97
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen, Section2.3: 28
28 . Show that the function f (x) = e x from the set of real numbers to the set of real
numbers is not invertible, but if the codomain is restricted to the set of positive real
numbers, the resulting function is invertible.

98
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen, Section2.3: 39
Show that the function f (x) = ax + b from R to R is
invertible, where a and b are constants, with a = 0, and
find the inverse of f .

99
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
We simply solve the equation y = ax + b for x.
This gives x = (y - b) /a, which is well-defined since a  0.
Thus the inverse is f-1 (y) = (y-b)/a.
To check that our work is correct, we must show that f of- 1 (y) = y
for all y  R and that f-1◦f(x) = x for all x  R.
Both of these are straightforward algebraic manipulations.
For the first, we have f ◦ f-1 (y) = f(f-1 (y)) = f((y- b)/a) = a((y- b)/a) + b = y.
The second is similar.

100
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Rosen, Section2.3: 70
70 . Suppose that f is an invertible function from Y to Z and g is an invertible function
from X to Y . Show that the inverse of the composition f ◦ g is given by
(f ◦ g)−1 = g−1 ◦ f −1.
g−1 ◦ f −1(z) = g−1 (f −1(z)) = g(-1) (y) = x

101
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The Identity Function
• For any domain A, the identity function I:AA
(variously written, IA, 1, 1A) is the unique
function such that aA: I(a)=a.
• Some identity functions you’ve seen:
– ing with T, ing with F, ing with , ing with
U.
• Note that the identity function is both one-to-
one and onto (bijective).
102

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Identity Function Illustrations
• The identity function:


• • y
• •
• •
• •

Domain and range x

103

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Graphs of Functions
Let f be a function from the set A to the set B. The graph of the function
f is the set of ordered pairs {(a, b) | a ∈ A and f (a) = b}.
For functions over numbers, we can represent an ordered pair (x,y) as a point on
plane. A function is then drawn as a curve (set of points) with only one y for each x.
EXAMPLE:

104

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Rosen, Section2.3:
62.Draw the graph of the function f (n) = 1 − n2 from Z to Z.

63. Draw the graph of the function f (x) = 2x from R to R.

64.Draw the graph of the function f (x) = x/2 from R to R.

65.Draw the graph of the function f (x) = x + x/2 from R to R.

66.Draw the graph of the function f (x) = x+ x/2 from R to R.

105
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
65.Draw the graph of the function f (x) = x + x/2 from R to R.

106
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Floor and Ceiling Functions
The floor function assigns to real number x the largest
integer that is less than or equal to x.
The value of the floor function at x is denoted by ⎣x⎦ .
The ceiling function assigns to the real number x the
smallest integer that is greater than or equal to x.
The value of the ceiling function at x is denoted by ⎡x⎤ .
Example

⎣3.125⎦ = 3 and ⎡3.125⎤ = 4


107
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Visualizing Floor & Ceiling
• Real numbers “fall to their floor” or “rise to
their ceiling.”
• Note that if xZ, 3
2 . 1.6=2

x   x & . 1.6

1 .
x   x 1.6=1

0
• Note that if xZ, 1 . 1.4= 1

. 1.4
x = x = x. 2 .
1.4= 2

3 3 .. .
3=3= 3

108

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


Rosen, Section2.3: 9
9. Find these values.
a 3/4 =1
b) 7/8=0
c)  3/4= 0 [-1<-0.75<0]
d)  7/8 = -1 -1<-7/8<0
e) 3
f) 1=-1
g 1/2+ 3/2 
h) 1/2 . 5/2  

109
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
The floor function rounds down and the ceiling function rounds
up.
a) 1
b) 0
c) 0
d) -1
e)3
f)-1
g) 1/2+ 3/2  = 1/2+ 2 = 2 1/2 =2
h) 1/2 . 5/2   = 1/2 . 2= 1  =1

110
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Plots with floor/ceiling: Example
• Plot of graph of function f(x) = x/3:
f(x)

Set of points (x, f(x)) +2

3 +3 x
2

111

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956


112
Rosen, Section2.3: 73
Prove or disprove each of these statements about the floor and ceiling
functions.
a)  x  = x for all real numbers x.
b) 2 = 2x whenever x is a real number.
c) x  +y  −x + y  = 0 or 1 whenever x and y are real numbers.
d) xy  =x  y  for all real numbers x and y.
e)  x /2  = (x+1)/2 for all real numbers x.

113
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
a) This is true. Since x is already an integer,  x  = x .

b) A little experimentation shows that this is not always true.


To disprove it we need only produce a counterexample, such as x = 1/2. In that case the left-hand
side is 1 = 1, while the right-hand side is 2. 0 = 0.

c) This is true. We prove it by cases. If x is an integer, then by identity (4b) in Table 1,


we know ,  x+y = x + , y , and it follows that the difference is 0. Similarly, if y is an integer. The
remaining case is that x = n + ε and y = m + δ, where n and m are integers and ε and δ are positive real
numbers less than 1 . Then x + y will be greater than m + n but less than m + n + 2, so f x + y l will be either
m + n + 1 or m + n + 2. Therefore the given expression will be either (n + 1) + (m + 1) - (m + n + 1) = 1 or (n
+ 1) + (m + 1) - (m + n + 2) = 0, as desired.

d) This is clearly false, as we can find with a little experimentation.


Take, for example, x = 1/10 and y = 3.
Then the left-hand side is  3/10  = 1, but the right-hand side is 1 · 3 = 3.

e) Again a little trial and error will produce a counterexample.


Take x = 1/2. Then the left-hand side is 1 while the right-hand side is 0.
114
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
How many bytes are required to encode n bits of
data where n equals
a) 7?
b) 17?
c) 1001?
d) 28,800?

115
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution
Since a byte is eight bits, all we are asking for in
each case is ⎡f n/8 ⎤ , where n is the number
of bits.
a) ⎡ f7/8 ⎤ = 1
b) ⎡ f17/8 ⎤ = 3
c) ⎡ f1001/8 ⎤ = 126
d) ⎡ f28800/8 ⎤ = 3600

116
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Thank you

117
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956

You might also like