COS1501 Content summary and discussion
COS1501 Content summary and discussion
COS1501
THEORETICAL COMPUTER SCIENCE 1
School of Computing
CONTENTS
Union: A B = {x | x A or x B}
Intersection: A B = {x | x A and x B}
Difference: A − B = {x | x A and x B}
Complement: A = {x | x U and x A}
A B A B A B
A+B
A B
A'
A B
C
Question 1
Use Venn diagrams to investigate whether, for all A,B,C U,
A (B C) = (A + B) − C.
If an identity, give proof; if not, give a counterexample.
Solution: Left-hand side:
B C’ B n C’
A B A B
A B
C C
Is A (B C) = (A + B) − C an identity?
Left-hand side:
A B n C’ A U (B n C ’)
A B A B A B
C C C
Right-hand side (A + B) − C:
A+B C (A + B) - C
A B A B A B
C C C
LHS ≠ RHS:
A (B C) = (A + B) − C is not an identity.
Provide counterexample.
Left-hand side: Right-hand side:
A U (B n C ’) (A + B) - C
A B A B
C C
Example:
Suppose A = {2, 3, 4} and B = {5, 6}, then
A × B = { (2, 5), (2, 6), (3, 5), (3, 6), (4, 5), (4, 6) }
Question 1b)
Determine whether, for all X, Y, W U,
( X − Y ) W ( X W ) − ( Y W ).
Solution:
Suppose ( p, q ) ( X − Y ) W (Cartesian product)
then p ( X − Y ) and q W
i.e. ( p X and p Y ) and q W
i.e. ( pX and qW ) and ( pY and qW )
i.e. ( p, q ) ( X W ) and ( p, q ) ( Y W )
i.e. ( p, q ) ( X W ) − ( Y W ).
Thus ( X − Y ) W ( X W ) − ( Y W ).
Handy notations:
Equivalence classes:
[x] = {y | y A and x R y}
Say [x1] & [x2] eq. classes of R: [x1], [x2] A,
then
P = {[x1], [x2]} is a partition of A:
1. [x1] ≠ , [x2] ≠ ,
2. [x1] [x2] = , and 3. [x1] [x2] = A
Question 2a)
R on Z: (x, y) R iff y - x is even.
Prove: R an equivalence relation. Show equivalence classes.
Solution:
Eq. rel: Reflexive on Z, symmetric & transitive
y - x is even, i.e. multiple of two, so
y - x = 2k for some k Z.
Try x = ..-4,-2, 2, 4,.. then ...= [-4] = [-2] = [0] = [2] = [4] =...
Try x = ..-3,-1,3,5,.. then … = [-3] = [-1] = [1] = [3] = [5] =…
( 3, 4 ) R (4 is not a multiple of 3)
R is a weak partial order on Z because R is reflexive
on Z, antisymmetric, and transitive.
R not trichotomous:Counterex: (3,4)R and (4,3) R
Graph for f:
Consider function h: A → B:
h injective: if h(a1) = h(a2) then a1 = a2
h surjective: ran(h) = B
h bijective iff h injective & surjective
Images
Solution:
f not bijective: injective (one-to-one); but
not surjective (not onto).
f injective:
Suppose f(u) = f(v) for some u, v Z,
then 3u – 1 = 3v – 1 i.e. u = v.
f not surjective: Counterexample:
Choose y = 3.
There is no x Z such that f(x) = y,
i.e. such that 3x – 1 = 3. (x = 4/3 Z.)
Hence 3 ran(f) and thus ran(f) Z.
Question 3 c) Determine inverse of bijective function g.
Solution: (y, x) g-1 iff (x, y) g
iff y = 3 – x
iff x = 3 – y
• commutative:
x y = y x for all x, y X.
• associative:
(x y) z = x (y z) for all x, y, z X.
• an identity element:
e x = x e = x for all x X.
Question 4
Let X = { b, c, d }
ai) Give example of binary operation * on X in a table:
* is commutative & has identity element.
* b c d * b c d
b b c d b b c d
c c c c c c c c
d d c d d d c d
Commutative: Symmetry around diagonal from top
left to bottom right corner. b is the identity element.
Question 4 Let X = { b, c, d }
aii) Show that your operation has both these properties,
and name the identity element. Solution:
Commutative
b * b = b = b * b; b*c = c = c*b
b * d = d = d * b; c*c = c = c*c
c * d = c = d * c; d*d = d = d*d
Check commutativity:
Diagonal top left to bottom right.
* b c d
Identity element: b, because b b c d
b*b = b = b * b, c c c c
c*b = c = b * c, and
d*b = d = b * d. d d c d
Question 4 Let X = { b, c, d }
bi) Let Y = {, {}}. Complete the following table for the
binary operation (intersection) on Y:
(Note:
= { } ( has no elements) and
{} has one element namely , so and {} has no
common elements, thus {} = .)
Solution:
{}
{} {}
Question 4 Let Y = {, {}}
{}
bii) Write in list notation.
{} {}
Solution:
= , so ( (,), ) is an element in the set;
{} = , so ( (,{}), ) is an element in set;
etc.
in list notation:
{ ( (,), ), ( (,{}), ), ( ({},), ),
( ({},{}), {} ) }
Logic (Study Guide, pp. 135 – 165)
Connectives for declarative disjunction
statements p & q: , , →, p q
p q
conjunction
p q T T T
pq
T F T
T T T
F T T
T F F
F F F
F T F
F F F biconditional
p q
pq
conditional
p q T T T
p→q
T F F
T T T
F T F
T F F
F T T F F T
F F T
Declarative statement True or False
Compound statement always true: tautology
Compound statement always false: negation
De Morgan’s laws:
• ¬ (p q) ¬ p ¬ q
• ¬ (p q) ¬ p ¬ q
NOTE: p → q ¬ p q
Universal quantifiers e.g.:
• “For all x Z …” i.e. “∀ x Z …”
Existential quantifiers e.g.:
• “There exists an x Z …” i.e.“∃ x Z …”
Predicate P(x):
P(x) is true for any variable x A that satisfies the
property, and P(x) is false otherwise.
Eg if P(x) is the pred. “x is an even integer”: P(x) is
True ∀ even integers and false ∀ odd integers.
Negation:
• ¬ (∀ x A, P(x)) i.e. ∃ x A, ¬ P(x)
• ¬ (∃ x A, P(x)) i.e. ∀ x A, ¬ P(x)
Question 5a)
Write the English sentence
‘If the wind is blowing then it will bring wind or rain’
in symbolic logic notation.
Use
the letter t for ‘the wind is blowing’,
the letter d for ‘it will bring wind’ and
the letter h for ‘it will bring rain’.
Solution:
Symbolic logic notation:
t → (d h)
Question 5b)
Use the double negation property and De
Morgan’s laws to rewrite the following expression
as an equivalent statement that does not have the
not symbol (¬) outside parentheses.
¬ (q (¬ q p))
Solution:
¬ (q (¬ q p))
¬ q ¬ (¬ q p) De Morgan’s law
¬ q (¬ ¬ q ¬ p) De Morgan’s law
¬ q (q ¬ p) Double negation
Question 5c)
Use a truth table to determine whether the compound statement
( ¬p q ) [ ¬( p → q ) ]
is a tautology, a contradiction or neither.
Solution:
p q ¬p ¬p q p → q ¬(p → q) (¬p q)
[ ¬ (p → q) ]
T T F T T F F
T F F F F T F
F T T T T F F
F F T T T F F
Solution:
(To prove: (¬q) → (¬p),
i.e. if n is not odd, then 5n2 is not odd,
i.e. if n is even then 5n2 is even.)
Ex. of factorisation:
x2 – 4x + 3 < 0
i.e. (x – 3)(x – 1) < 0
then (x – 3) > 0 and (x – 1) < 0 (pos. nr neg. nr = neg. nr)
i.e. x > 3 and x < 1 ___1______3____ impossible
OR
(x – 3) < 0 and (x – 1) > 0
i.e. x < 3 and x > 1, ___1______3____
i.e. 1 < x < 3.
Question 6 Let A = { 1, 2, 3 }, B = { 0, 1 } and C = { }.
a) Give A + B and an equivalence relation on A + B (not identity relation).
B C = ; hence Ƥ (B C) = { }.
Ƥ (B) – Ƥ (C) = { { 0 }, { 1 }, { 0, 1 } }
Ƥ (B) + Ƥ (C) = { {}, { 0 }, { 1 }, { 0, 1 } }
Question 6 Let A = { 1, 2, 3 }, B = { 0, 1 } and C = { }.
c) Give injective function on B B.
Solution:
BB = { (0, 0) , (0, 1) , (1, 0) , (1, 1) };
Injective function on BB :
{((0,0), (0,0)), ((0, 1), (0, 1)), ((1, 0), (1, 0)), ((1, 1), (1, 1))}
d) Give example of surjective function from B B to B C.
Solution: Surjective: Ran(f) = B C. Function: Each member
of BB must appear only once as first co-ordinate.