BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
CHAPTER 8: LOGIC, SETS AND FUNCTIONS
1. INTRODUCTION TO LOGIC
Propositions and Truth Values
A proposition is a declarative statement which is either true or
false, but not both simultaneously. Examples of propositions are:
1. The earth is flat.
2. 29 is a prime number.
3. 3 + 2 = 4.
4. 6 < 24.
5. Tomorrow is my birthday.
Exclamation, questions and demands are not propositions:
6. Keep of the grass.
7. Long live the Queen!
8. Did you go to Aditya’s party?
The truth (T) or falsity (F) of a proposition is called truth value.
Definition 1: Proposition (p): true = T (or 1) or false = F (or 0)
(binary logic)
Definition 2: Negation (¬): ‘not p’
Example 1:
p : I am going to town
1
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
¬p : I am not going to town;
It is not the case that I am going to town.
Truth Table:
p ¬p
T F
F T
Definition 3: Conjunction (∧): ‘and’
Example 2:
p : ‘I am going to town’
q : ‘It is going to rain’
p ∧ q : ‘I am going to town and it is going to rain.’
Truth Table:
p q p∧q
F F F
F T F
T F F
T T T
Note: Both p and q must be true!!!!!
Definition 4: Disjunction (∨): ‘or’
Example 3:
p : ‘I am going to town’
q : ‘It is going to rain’
p ∨ q : ‘I am going to town or it is going to rain.’
2
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
Truth Table:
p q p∨q
F F F
F T T
T F T
T T T
Note: Only one of p, q need be true.
Definition 5: Exclusive OR (⊕): True when exactly one of p and
q is true.
Example 4:
p : ‘I am going to town’
q : ‘It is going to rain’
p ⊕ q : ‘Either I am going to town or it is going to rain.’
Truth Table:
p q p⊕q
F F F
F T T
T F T
T T F
Note: Only one of p and q must be true.
Definition 6: Implication (→): ‘If...then...’
Example 5:
p : ‘I am going to town’
q : ‘It is going to rain’
p → q : ‘If I am going to town then it is going to rain.’
3
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
Truth Table:
p q p→q
F F T
F T T
T F F
T T T
Note: The implication is false only when p is true and q is false!
Terminology:
p = premise, hypothesis, antecedent
q = conclusion, consequence
More terminology:
q → p is the CONVERSE of p → q
¬q → ¬p is the CONTRAPOSITIVE of p → q
Example 6:
Find the converse of the following statement:
R: ‘Raining tomorrow is a sufficient condition for me not going to
town.’
Step 1: Assign propositional variables for the above statement.
p : It will rain tomorrow
q : I will not go to town
Step 2: Symbolize the assertion
R: p→q
Step 3: Symbolize the converse
q→p
Step 4: Convert the symbols back into words
‘If I don’t go to town then it will rain tomorrow’
4
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
Definition 7: Biconditional (↔): ‘…if and only if…’
Example 7:
p : ‘I am going to town’
q : ‘It is going to rain’
p ↔ q : ‘I am going to town if and only if it is going to rain.’
Truth Table:
p q p↔q
F F T
F T F
T F F
T T T
Note: Both P and Q must have the same truth value.
Breaking assertions into component propositions - look for the
logical operators!
Example 8:
‘If I go to UTeM or go to the hostel then I will not go shopping.’
Solution
p : I go to UTeM
q : I go to the hostel
r : I will go shopping
If......p......or.....q.....then....not.....r
(p ∨ q) → ¬r
5
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
2. PROPOSITIONAL EQUIVALENCES
Definition 1: Tautology: A tautology is a compound proposition
which is always true no matter what the truth value
of its components.
Definition 2: Contradiction: A contradiction is a compound
proposition which is always false no matter what
the truth value of its components.
Definition 3: Contingency: A contingency is a proposition which
neither a tautology nor a contradiction.
Definition 4: Logically equivalent (⇔ or ≡): Two compound
propositions are logically equivalent if they have
the same truth values in all cases.
Example 9:
Show that p ∨ ¬p is a tautology.
Solution
Constructing the truth table for p ∨ ¬p, we have:
p ¬p p ∨ ¬p
T F T
F T T
Note that p ∨ ¬p is always true (no matter what proposition is
substituted for p) and is therefore a tautology.
6
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
Example 10:
Show that ¬p ∨ ¬q and ¬(p ∧ q) are logically equivalent, i.e. that
(¬p ∨ ¬q) ≡ ¬(p ∧ q).
Solution
We draw up the truth table for ¬p ∨ ¬q and also for ¬(p ∧ q).
p q ¬p ¬q ¬p ∨ ¬q p∧q ¬(p ∧ q)
T T F F F T F
T F F T T F T
F T T F T F T
F F T T T F T
Comparing the columns for ¬p ∨ ¬q and for ¬(p ∧ q) we note that
the truth values are the same. Hence ¬p ∨ ¬q and ¬(p ∧ q) are
logically equivalent propositions.
3. PREDICATES AND QUANTIFIER
A predicate is a sentence containing variables which is either true
or false depending on the values assigned to the variables. For
example, let P( x) be the predicate x is an integer satisfying x = x2 .
It is true for x = 0 and x = 1, and false for all other values of x.
In the previous sections, we studied different types of logical
operations. There are further logical operators, known as
quantifiers, which when applied to a predicate, produce either a
true proposition or a false proposition.
7
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
Definition 1: Universal quantifier: the symbol ∀ is called the
universal quantifier and
∀x is read as ‘for all x’ or ‘for every x’.
Definition 2: Existential quantifier: the symbol ∃ is called the
existential quantifier and
∃x is read as ‘there exist at least one x’ or ‘for some x’.
Example 11:
Suppose P( x) is the predicate “x < |x|.” Determine the truth value
of ∀x P( x) , where the universe for x is:
(a) the three numbers −3,−2,−1.
(b) all real numbers.
Solution
(a) P(−3), P(−2), and P(−1) are all true because the numbers
−3,−2,−1 are negative but their absolute values are positive.
Therefore, ∀x P( x) is true.
(b) The predicate x < |x| is false for every nonnegative number.
For example, P(1) is false because 1 = |1|. Having one value of
x that makes the predicate false is enough to guarantee that
∀x P( x) is false.
Example 12:
Suppose P( x) is the predicate “x < |x|.” Determine the truth value
of ∃x P( x) where the universe for x is:
(a) the three numbers 1, 2, 3.
(b) the six numbers −2,−1, 0, 1, 2, 3.
8
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
Solution
(a) P(1), P(2), and P(3) are all false because in each case x = |x|.
Therefore, ∃x P( x) is false for this universe.
(b) If we begin checking the six values of x, we find P(−2) is
true — it states that −2 < −2 , or −2 < 2. We need not check
further; having one case that makes the predicate true is
enough to guarantee that ∃x P( x) is true.
4. SETS AND SET OPERATIONS
A set is a collection of objects and these objects are called the
elements of the set.
• {Liverpool, Arsenal, Blackburn}
• {2, 3, 5, 7 ,11}
• {cheese, eggs, milk, cream}
We usually denote a set by a capital letter for reference purpose.
For instance, V = {a, e, i, o, u} is the set V containing vowels.
Notation:
x is an element of set S: x ∈ S.
x is not an element of set S: x ∉ S.
9
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
For a large set, especially an infinite set, we cannot write down all
the elements and so formally we write
S = {x : P(x)}
to denote the set of objects x for which the predicate P(x) is true.
For example,
S = {x : x is an odd positive integer} describes the set S = {1, 3, 5,
7 , …}
Common Universal Sets
• R = real numbers
• N = natural numbers = {0,1, 2, 3, . . . }, the counting numbers
• Z = all integers = {. . , -3, -2, -1, 0, 1, 2, 3, 4, . .}
• Z+ is the set of positive integers
Subsets
Definition 1: The set A is a subset of the set B, denoted A ⊆ B, iff
∀x[x ∈A→x ∈B]
Definition 2: The empty set or the null set, denoted ∅ or { }, is the
set with no members.
Note: 1. ∅ is a subset of every set and
2. a set B is always a subset of itself.
10
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
Definition 3: The set of all subset of a set A, denoted P(A), is
called the power set of A.
Example 13:
If A = {a, b} then P(A) = {∅, {a}, {b}, {a,b}}
Definition 4: The number of (distinct) elements in A, denoted |A|,
is called the cardinality of A.
Example 14:
A = {a, b},
|{a, b}| = 2 and |P({a, b})| = 4.
Useful Fact: |A|=n implies |P(A)| = 2n
Definition 5: The Cartesian product of A with B, denoted A×B,
is the set of all the ordered pairs {(a, b) | a ∈A ∧ b∈B}
Example 15:
A = {a,b}, B = {1, 2, 3}
AxB = {(a, 1), (a, 2), (a, 3), (b, 1), (b, 2), (b, 3)}
11
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
Set Operations
There is always a universal set U. All sets are assumed to be
subsets of U.
Definitions:
• The union of A and B, denoted A ∪ B, is the set of all elements
which belong to A or to B or to both. {x | x∈A ∨ x∈B}
• The intersection of A and B, denoted A ∩ B, is the set of all
elements which belong both to A and B. {x | x∈A ∧ x∈B}
Note: If the intersection of set A and B is empty, A and B are
said to be disjoint.
• The complement of A, denoted A , is the set which consist all the
elements in U which do not belong to A. {x | ¬(x∈A)} or
{x|x∉A}.
12
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
• The difference of A and B, denoted A - B, is the set containing
those elements that are in A but not in B. {x | x∈A ∧ x∉B} or
A∩ B
Example 16:
U = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, A= {1, 2, 3, 4, 5}, B = {4, 5,
6, 7, 8}. Then
• A ∪ B = {1, 2, 3, 4, 5, 6, 7, 8}
• A ∩ B = {4, 5}
• A = {0, 6, 7, 8, 9, 10}
• B = {0, 1, 2, 3, 9, 10}
• A - B = {1, 2, 3}
• B - A = {6, 7, 8}
5. FUNCTIONS
Let A and B be sets. A function f maps set A to set B, denoted f :
A→ B is a relation in which every element of A is associated with
a uniquely specified element of B. In other words, for each a ∈ A,
there is unique element b given in the form f (a) = b, where b ∈ B.
Note: f associates each a in A with one and only one b in B.
A is called the domain and
B is called the codomain.
13
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
If f (a) = b
• b is called the image of a under f
• a is called a pre-image of b
(note there may be more than one pre-image of b but there is only
one image of a).
The range of f is the set of images of all the elements of A.
Example 17:
• f (a) = Z
• the image of d is Z
• the domain of f is A = {a, b, c, d}
• the codomain is B = {X, Y, Z}
• the range of f is {Y, Z}
• the preimage of Y is b
• the preimages of Z are a, c and d
Injections, Surjections and Bijections
Let f be a function from A to B.
Definition 1: f is one-to-one or injective if f(x) ≠ f(y) when x ≠ y.
Similarly if f(x) = f(y) then x = y. In other words,
different inputs give different output.
14
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
Definition 2: f is onto or surjective if for every b ∈ B, there exists
an element a ∈ A. This means that for every b in B
there must be an a in A such that f(a) = b.
Definition 3: f is bijective if it is surjective and injective (one-to-
one and onto).
Example 18:
Surjection but not an injection
Injection but not a surjection
Surjection and an injection, hence a bijection
15
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
Example 19:
Consider f : R → R defined by f ( x) = 3x − 7 . Show that f is
injective.
Solution
To show that f is an injection, we prove that for all real numbers x
and y, f (x) = f (y) implies x = y.
Let
f ( x) = f ( y )
3x − 7 = 3 y − 7
3x = 3 y
x= y
so f is injective.
Inverse Functions
Let f be a function from A to B. Then the inverse of f, denoted
f −1, is the function from B to A defined as
f −1 (y) = x iff f(x) = y
Example 20:
Let f be defined by the diagram:
Note: No inverse exists unless f is a bijection.
16
BACS 1253 Mathematics for computer science 1(linear algebra)
Faculty of Information and Communications & Technology
____________________________________________________________________________________________________________
Composition Functions
Let f: B→C, g: A→B. The composition of f with g, denoted f o g ,
is the function from A to C defined by f o g ( x) = f ( g ( x) ) .
Example 21:
If f ( x) = x2 and g ( x) = 2 x +1, then find f o g ( x) and g o f ( x) .
Solution
f o g ( x) = f ( g ( x) ) g o f ( x) = g ( f ( x) )
2
= ( g ( x) ) and = 2 ( f ( x) ) + 1
= (2 x +1)2 = 2 x2 +1
17