COMP232 - Mathematics for Computer Science

COMP232 - Mathematics for Computer Science
Tutorial 7
Ali Moallemi
moa [email protected]
Iraj Hedayati
h [email protected]
Concordia University, Winter 2016
Ali Moallemi, Iraj Hedayati
COMP232 - Mathematics for Computer Science
1 / 13
Table of Contents
1
2.3 Functions
Exercise 1
Exercise 2
Exercise 10
Exercise 11
Exercise 14
Exercise 15
Exercise 20
Exercise 30
Exercise 32
Exercise 40
Ali Moallemi, Iraj Hedayati
COMP232 - Mathematics for Computer Science
2 / 13
Exercise 1
Why is f not a function from R to R if
a) f (x) = x1
Answer:
f (0) is not defined
√
b) f (x) = x
Answer:
f (x) is not defined for x < 0
p
c) f (x) = ± (x2 + 1)
Answer:
HINT: f is a function if and only if for every input there is only one
identical output.
f (x) is not well-defined because there are two distinct values assigned
to each x
Ali Moallemi, Iraj Hedayati
COMP232 - Mathematics for Computer Science
3 / 13
Exercise 2
Determine whether f is a function from Z to R if
a) f (n) = ±n
Answer: NO
for every n there are two distinct answers
√
b) f (n) = n2 + 1
Answer:YES
For every n in Z, n2 + 1 is positive and there is an identical answer.
c) f (n) = n21−4
Answer: NO
For n = ±2, the function is not defined
Ali Moallemi, Iraj Hedayati
COMP232 - Mathematics for Computer Science
4 / 13
Exercise 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
Answer: YES
b) f (a) = b, f (b) = b, f (c) = d, f (d) = c
Answer: NO
because f (a) = f (b) = b
c) f (a) = d, f (b) = b, f (c) = c, f (d) = d
Answer: NO
because f (a) = f (d) = d
Ali Moallemi, Iraj Hedayati
COMP232 - Mathematics for Computer Science
5 / 13
Exercise 11
Which functions in Exercise 10 are onto?
a) f (a) = b, f (b) = a, f (c) = c, f (d) = d
Answer: YES
b) f (a) = b, f (b) = b, f (c) = d, f (d) = c
Answer: NO
because 6 ∃x ∈ {a, b, c, d} (f (x) = a)
c) f (a) = d, f (b) = b, f (c) = c, f (d) = d
Answer: NO
because 6 ∃x ∈ {a, b, c, d} (f (x) = a)
Ali Moallemi, Iraj Hedayati
COMP232 - Mathematics for Computer Science
6 / 13
Exercise 14
Determine whether f : Z × Z → Z is onto if
a) f (m, n) = 2m − n
Answer: YES, let m = 0 and −n will cover entire Z
b) f (m, n) = m2 − n2 .
Answer: NO HINT:m2 , n2 = {0, 1, 4, 9, . . .}
A counterexample can be 2. 6 ∃m, n ∈ Z (m2 − n2 = 2).
c) f (m, n) = m + n + 1
Answer: YES, let n = −1 and m will cover entire Z
d) f (m, n) = |m| − |n|.
Answer: YES
if n = 0, m will cover positive members of Z
if m = 0, n will cover negative members of Z
e) f (m, n) = m2 − 4
Answer: NO, m2 − 4 ≥ −4 and it will not cover members of Z less
than -4
Ali Moallemi, Iraj Hedayati
COMP232 - Mathematics for Computer Science
7 / 13
Exercise 15
Determine whether f : Z × Z → Z is onto if
a) f (m, n) = m + n
Answer: YES, let n = 0 and m will cover entire Z
b) f (m, n) = m2 + n2
Answer: NO m2 + n2 ≥ 0 and it will not cover members of Z less
than 0
c) f (m, n) = m
Answer: YES
d) f (m, n) = |n|
Answer: NO |n| ≥ 0 and it will not cover members of Z less than 0
e) f (m, n) = m − n
Answer: YES, let n = 0 and m will cover entire Z
Ali Moallemi, Iraj Hedayati
COMP232 - Mathematics for Computer Science
8 / 13
Exercise 20
Give an example of a function from N to N that is
a) one-to-one but not onto.
Answer: f (n) = 2n
b) onto but not one-to-one.
Answer: f (n) = dn/2e
c) both onto and one-to-one
(but different from the identity function).
(
n+1
if n is odd
Answer: f (n) =
n−1
if n is even
d) neither one-to-one nor onto.
√
Answer: f (n) = d ne + 1
Ali Moallemi, Iraj Hedayati
COMP232 - Mathematics for Computer Science
9 / 13
Exercise 30
Let S = {−1, 0, 2, 4, 7}. Find f (S) if
a) f (x) = 1.
Answer: f (S) = {1}
b) f (x) = 2x + 1.
Answer: f (S) = {−1, 1, 5, 9, 15}
c) f (x) = dx/5e.
Answer: f (S) = {0, 1, 2}
d) f (x) = b(x2 + 1)/3c.
Answer: f (S) = {0, 1, 5, 16}
Ali Moallemi, Iraj Hedayati
COMP232 - Mathematics for Computer Science
10 / 13
Exercise 32
Let f (x) = 2x where the domain is the set of real numbers. What is
a) f (Z).
Answer: The set of all even numbers
b) f (N).
Answer: The set of all positive even numbers
c) f (R).
Answer: R
Ali Moallemi, Iraj Hedayati
COMP232 - Mathematics for Computer Science
11 / 13
Exercise 40
Let f be a function from the set A to the set B. Let S and T be subsets
of A. Show that
a) f (S ∪ T ) = f (S) ∪ f (T ).
Answer:
⇒)
∀y∃x y ∈ f (S ∪ T ) → x ∈ S ∪ T ∧ f (x) = y
⇒ ∀y∃x y ∈ f (S ∪ T ) → x ∈ S ∨ x ∈ T ∧ f (x) = y
⇒ ∀y y ∈ f (S ∪ T ) → y ∈ f (S) ∨ y ∈ f (T )
⇒ ∀y y ∈ f (S ∪ T ) → y ∈ f (S) ∪ f (T )
⇒ f (S ∪ T ) ⊆ f (S) ∪ f (T )
⇐)
(S ⊆ S ∪ T ) ∧ (T ⊆ S ∪ T )
⇒ (f (S) ⊆ f (S ∪ T )) ∧ (f (T ) ⊆ f (S ∪ T ))
⇒ f (S) ∪ f (T ) ⊆ f (S ∪ T )
Ali Moallemi, Iraj Hedayati
COMP232 - Mathematics for Computer Science
12 / 13
Exercise 40
Let f be a function from the set A to the set B. Let S and T be subsets
of A. Show that
b) f (S ∩ T ) ⊆ f (S) ∩ f (T ).
Answer:
(S ∩ T ⊆ S) ∧ (S ∩ T ⊆ T )
⇒ (f (S ∩ T ) ⊆ f (S)) ∧ (f (S ∩ T ) ⊆ f (T ))
⇒ f (S ∩ T ) ⊆ f (S) ∩ f (T )
Ali Moallemi, Iraj Hedayati
COMP232 - Mathematics for Computer Science
13 / 13