You are on page 1of 55

Discrete structures

What is discrete mathematics? Discrete


mathematics is the part of mathematics
devoted to the study of discrete objects.
(Here discrete means consisting of
distinct or unconnected elements.)

The kinds of problems solved using


discrete mathematics include:
- How many ways are there to choose a
valid password on a computer
system?
- What is the probability of winning a
lottery?
- Is there a link between two computers
in a network?
- How can I identify spam e-mail
messages?
- How can I encrypt a message so that
no unintended recipient can read it?
- What is the shortest path between two
cities using a transportation system?
- How can a list of integers be sorted so
that the integers are in increasing
order?
- How many steps are required to do
such a sorting?
- How can it be proved that a sorting
algorithm correctly sorts a list?
- How can a circuit that adds two
integers be designed?
- How many valid Internet addresses
are there?

You will learn the discrete structures and


techniques needed to solve problems
such as the above stated problems.
Primary goals of this course is to teach
mathematical reasoning and problem
solving, rather than a discrete set of
skills.
1. you can develop your
mathematical maturity: that is, your
ability to understand and create
mathematical arguments

2. Discrete mathematics provides the


mathematical foundations for many
computer science courses including
data structures, algorithms, database
theory, automata theory, formal
languages, compiler theory, computer
security, and operating systems.
3. discrete mathematics contains the
necessary mathematical background
for solving problems in operations
research
1. The Foundations: Logic and
Proofs
- The rules of logic specify the meaning
of mathematical statements.
- Logic is the basis of all mathematical
reasoning, and of all automated
reasoning. It has practical applications
to the design of computing
machines, to the specification of
systems, to artificial intelligence, to
computer programming, to
programming languages, and to
other areas of computer science, as
well as to many other fields of study.

1.1 Propositional Logic


Introduction
- The rules of logic give precise
meaning to mathematical statements.
These rules are used to distinguish
between valid and invalid
mathematical arguments.
- The Importance of logic in
understanding mathematical
reasoning
- Construction of computer programs
and design of computer circuit, are
part of logics.

Definition of logics

oLogic n.1. The branch of


philosophy concerned with
analysing the patterns of reasoning
by which a conclusion is drawn
from a set of premises, without
reference to meaning or context
(Collins English Dictionary)

oTruth Table
• A combination of Propositional
variables and connectives form a truth
table.
• For example the following table
shows the relationship between the
values of P, Q

 Proposition:
- A proposition is a declarative
sentence (that is, a sentence that
declares a fact) that is either true or
false, but not both.
- It is the basic building blocks of logic

EXAMPLE 1: All the following


declarative sentences are propositions.
1. Nairobi , is the capital city of the
kenya.
2. Kisumu is the capital of Kenya.
3. 1 + 1 = 2.
4. 2 + 2 = 3.
- Propositions 1 and 3 are true,
whereas 2 and 4 are false.

EXAMPLE 2 :Consider the following


sentences.
1. What time is it?
2. Read this carefully.
3. x + 1 = 2.
4. x + y = z.
- Sentences 1 and 2 are not
propositions because they are not
declarative sentences. Sentences 3
and 4 are not propositions because
they are neither true nor false. Note
that each of sentences 3 and 4 can
be turned into a proposition if we
assign values to the variables.
More examples
(i) (gross man)
(ii) ‘Where are you going?’
(iii) ‘Come here.’
(iv) ‘This sentence is false.’
(v)
(vi) Canberra is the capital of Australia.’
(vii) ‘There are 8 days in a week.’
(viii)‘Isaac Newton was born in 1642.’
(ix) ‘5 is greater than 7.’
(x) ‘Every even number greater than 2 can
be expressed as the sum of
(xi) two prime numbers.’

(xii) Ice floats in water.


(xiii)(2 + 2 = 4
(xiv) China is in Europe.
(xv) 2 + 2 = 5
(xvi) Where are you going?
(xvii) Do your homework.

 Propositional variables (or


statement variables):
- These are variables that represent
propositions
- The conventional letters are used for
propositional variables are p, q, r, s, .
- The truth value of a proposition is
true, denoted by T, if it is a true
proposition, and the truth value of a
proposition is false, denoted by F, if it
is a false proposition.
- Many mathematical statements are
constructed by combining one or
more propositions.
- The area of logic that deals with
propositions is called the
propositional calculus or
propositional logic.

Facts about proposition


- It must be either true or false
- cannot be both true and false
- We use T to denote True and F to
Denote False

Propositions and connectives


 Compound propositions
o Are propositions formed from
existing propositions using logical
operators
 Connectives/logical operators:
are symbols used to combine
propositions to form compound
propositions. They include:
Negation, Conjunction, Disjunction

 Negation:
DEFINITION 1: Let p be a proposition.
The negation of p, denoted by¬p (also
denoted by p), is the statement
- “It is not the case that p.”
The proposition ¬p is read “not p.” The
truth value of the negation of p, ¬p, is the
opposite of the truth value of p.
EXAMPLE 3 Find the negation of the
proposition
- “Michael’s PC runs Linux”
and express this in simple English.

Solution: The negation is


- “It is not the case that Michael’s PC
runs Linux.”
This negation can be more simply
expressed as
- “Michael’s PC does not run Linux.”

EXAMPLE 4: Find the negation of the


proposition
- “Vandana’s smartphone has at least
32GB of memory”
and express this in simple English.
Other examples
- (a1) Ice floats in water. (a2) It is false
that ice floats in water. (a3) Ice does
not float in water.
- (b1) 2 + 2 =5 (b2) It is false that 2 + 2
= 5. (b3) 2 + 2 _= 5
In general:
Negation
 Conjunction :
DEFINITION 2: Let p and q be
propositions. The conjunction of p and q,
denoted by p ∧ q, is the proposition
“p and q.” The conjunction p ∧ q is
true when both p and q are true and is
false otherwise.

Example if p denotes the proposition ‘Today


is Monday’, and q denotes the proposition
‘It is raining’, then we can write p ∧ q to
denote the proposition ‘Today is Monday
and it is raining
Note that: in logic the word “but”
sometimes is used instead of “and” in a
conjunction. For example, the statement
“The sun is shining, but it is raining” is
another way of saying “The sun is
shining and it is raining.”
EXAMPLE 5 Find the conjunction of
the propositions p and q where p is the
proposition “Rebecca’s PC has more than
16 GB free hard disk space” and q is the
proposition “The processor in Rebecca’s
PC runs faster than 1 GHz.”

Solution: The conjunction of these


propositions, p ∧ q, is the proposition
“Rebecca’s PC has more than 16 GB free
hard disk space, and the processor in
Rebecca’s PC runs faster than 1GHz.”
- This conjunction can be expressed
more simply as “Rebecca’s PC has
more than 16 GB free hard disk space,
and its processor runs faster than 1
GHz.” For this conjunction to be true,
both conditions given must be true. It
is false, when one or both of these
conditions are false. ▲
In general:
And /Conjunction:

 Or/ Disjunction:
A disjunction is true when at least one
of the two propositions is true. For
instance, the inclusive or is being used in
the statement.
p ∨ q means ‘p or q or both’.
- “Students who have taken calculus or
physics can take discrete structures.”

Here, we mean that students who have


taken both calculus and physics can take
the class, as well as the students who
have taken only one of the two subjects.
DEFINITION 3: Let p and q be
propositions. The disjunction of p and q,
denoted by p ∨ q, is the proposition “p or
q.” The disjunction p ∨ q is false when
both p and q are false and is true
otherwise.

EXAMPLE 6 What is the disjunction of


the propositions p and q where p and q
are the same propositions as
in Example 5?
Solution: The disjunction of p and q, p ∨
q, is the proposition
- “Rebecca’s PC has at least 16 GB free
hard disk space, or the processor in
Rebecca’s PC runs faster than 1
GHz.”

This proposition is true when Rebecca’s


PC has at least 16 GB free hard disk
space, when the PC’s processor runs
faster than 1 GHz, and when both
conditions are true. It is false when both
of these conditions are false, that is,
when Rebecca’s PC has less than 16 GB
free hard disk space and the processor in
her PC runs at 1 GHz or slower.▲

- As was previously remarked, the use


of the connective or in a disjunction
corresponds to one of the two ways
the word or is used in English,
namely, in an inclusive way. Thus, a
disjunction is true when at least one of
the two propositions in it is true.
In general:
Or/disjunction:

 Exclusive or
- Sometimes, we use or in an exclusive
sense. When the exclusive or is used
to connect the propositions p and q,
the proposition “p or q (but not both)”
is obtained.
- This proposition is true when p is true
and q is false, and when p is false and
q is true.
- It is false when both p and q are
false and when both are true.

Difference between inclusive and


exclusive OR
- If you are offered tea or coffee, you are
expected to choose one or the other, but
not both! This exclusive OR
- On the other hand, if a discount is
available to anyone who is a student or a
pensioner,
o it is presumably available to someone
who is both a student and a
pensioner-this inclusive OR
DEFINITION 4 Let p and q be
propositions. The exclusive or of p and q,
denoted by p ⊕ q, is the proposition that
is true when exactly one of p and q is
true and is false otherwise.

E.G: On the other hand, we are using the


exclusive or when we say
- “Students who have taken calculus or
computer science, but not both, can
enroll in this class.”

- Here, we mean that students who have


taken both calculus and a computer
science course cannot take the class.

-
-
- Only those who have taken exactly
one of the two courses can take the
class.

- Similarly, when a menu at a restaurant


states, “Soup or salad comes with an
entrée,”

o the restaurant almost always


means that customers can have
either soup or salad, but not both.
Hence, this is an exclusive, rather
than an inclusive, or.

In general:
Exclusive Or:
Conditional statement
If you pass you proceed to the next
year of course
 Consider the different possibilities that
could arise.
 If you pass the subject and progress to
the next year of your course, then clearly
your lecturer’s statement is true.
 If you pass the subject but don’t progress
to the next year of your course, then you
could accuse your lecturer of making a
false statement.
 if you fail the subject- Whether or not
you progress to the next year of your
course, you could not accuse your
lecturer of making a false statement.
NB the key to truth is passing

DEFINITION 5 Let p and q be


propositions. The conditional statement
p → q is the proposition “if p, then q.”
The conditional statement p → q is false
when p is true and q is false, and true
otherwise.

- In the conditional statement p → q, p


is called the hypothesis (or
antecedent or premise) and q is called
the conclusion (or consequence).

- The statement p → q is called a


conditional statement because p → q
asserts that q is true on the condition
that p holds. A conditional statement
is also called an implication.

- Note that the statement p → q is true


when both p and q are true and when
p is false (no matter what truth value
q has).

- Because conditional statements play


such an essential role in mathematical
reasoning, a variety of terminology is
used to express p → q. The
conditional statement can also be
expressed as follows:

o“if p, then q” “p implies


q”
o“if p, q” “p only if q”
o“p is sufficient for q” “a
sufficient condition for q is p”
o“q if p” “q whenever
p”
o“q when p” “q is
necessary for p”
o
o“a necessary condition for p is
q” “q follows from p”
o“q unless ¬p”
- Conditional Statement: pq is false
when p is true and q is false. True
otherwise

Example
- p: you go, q: I go. pq means “If you
go, then I go” is equivalent to p only
if q “You go only if I go” (not the
same as “I go only if you go” which is
q only if p).
In general
Condition

CONVERSE, CONTRAPOSITIVE,
AND INVERSE:
- We can form some new conditional
statements starting with a conditional
statement p → q.
- In particular, there are three related
conditional statements that occur so
often that they have special names.
 The proposition q → p is called
the converse of p → q.
 The contrapositive of p → q is
the proposition ¬q →¬p.
 The proposition ¬p →¬q is
called the inverse of p → q.
- We will see that of these three
conditional statements formed from p
→ q, only the contrapositive always
has the same truth value as p → q.

- We first show that the contrapositive,


¬q →¬p, of a conditional statement p
→ q always has the same truth value
as p → q.

- To see this, note that the


contrapositive is false only when ¬p
is false and ¬q is true, that is, only
when p is true and q is false.
- We now show that neither the
converse, q → p, nor the inverse, ¬p
→¬q, has the same truth value as p →
q for all possible truth values of p and
q.

- Note that when p is true and q is


false, the original conditional
statement is false, but the converse
and the inverse are both true.

- When two compound propositions


always have the same truth value we
call them equivalent, so that a
conditional statement and its
contrapositive are equivalent.

- The converse and the inverse of a


conditional statement are also
equivalent, as the reader can verify,
but neither is equivalent to the
original conditional statement.

NB: Take note that one of the most


common logical errors is to assume that
the converse or the inverse of a
conditional statement is equivalent to this
conditional statement.
- We illustrate the use of conditional
statements in Example 9.
EXAMPLE 9 What are the
contrapositive, the converse, and the
inverse of the conditional statement

“The home team wins whenever it is


raining?”
Solution: Because “q whenever p” is one
of the ways to express the conditional
statement
- p → q, the original statement can be
rewritten as
“If it is raining, then the home team
wins.”

- Consequently, the contrapositive of


this conditional statement is
“If the home team does not win, then it is
not raining.”
- The converse is
“If the home team wins, then it is
raining.”
- The inverse is
“If it is not raining, then the home team
does not win.”
- Only the contrapositive is equivalent
to the original statement.
 BICONDITIONALS

DEFINITION 6 Let p and q be


propositions. The biconditional
statement p ↔ q is the proposition “p if
and only if q.” The biconditional
statement p ↔ q is true when p and q
have the same truth values, and is false
otherwise.

- Biconditional statements are also


called bi-implications.

- Note that the statement p ↔ q is true


when both the conditional statements
p → q and q → p are true and is false
otherwise.
- That is why we use the words “if and
only if” to express this logical
connective and why it is symbolically
written by combining the
symbols→and←.

- There are some other common ways


to express p ↔ q:

o“p is necessary and sufficient for


q”
o“if p then q, and conversely”
o“p iff q.”

The last way of expressing the


biconditional statement p ↔ q uses the
abbreviation “iff” for
- “if and only if.” Note that p ↔ q has
exactly the same truth value as (p →
q) ∧ (q → p).

In general
Biconditional statement

Example 10:
• P: “you can take the flight”, q: “you
buy a ticket”
• P  q: “You can take the flight if
and only if you buy a ticket”
–This statement is true
• If you buy a ticket and take
the flight
• If you do not buy a ticket and
you cannot take the flight

Truth Tables of Compound


Propositions

Precedence of Logical Operators

Compound propositions
We now have the notation we need in
order to be able to write compound
propositions in symbolic form
Example 1
Express the proposition ‘Either my
program runs and it contains no bugs, or
my program contains bugs’ in symbolic
form.

Solution
Let p denote the statement: ‘My program
runs.’
Let q denote the statement: ‘My program
contains bugs.’

Then the proposition can be written in


symbolic form as follows
(p ∨¬q) ∨ q)
Notice in this example how parentheses
are used to group sub expressions within
the whole expression, just as in
arithmetic and algebra
Example 2
Construct the truth table for the
expression (p ∨¬q) ∨ q)

Exercise
Construct the truth table of the proposition
below
¬(p∧¬q)

TAUTOLOGIES AND
CONTRADICTIONS
TAUTOLOGY
An expression that is always true, regardless
of the truth values of the variables it
contains, is called a tautology
 Some propositions P(p, q, . . .) contain
only T in the last column of their truth
tables or, in other words, they are true
for any truth values of their variables.
 Such propositions are called
tautologies
Example p ∨¬p, is a tautology

CONTRADICTION
An expression that is always false,
regardless of the truth values of the variables
it contains, is called a contradiction

 a proposition P(p, q, . . .) is called a


contradiction if it contains only F in
the last column of its truth table or,
 in other words, if it is false for any
truth values of its variables.
Example p∧¬p, is a contradiction

Note that the negation of a tautology is a


contradiction since it is always false, and the
negation of a contradiction is a tautology
since it is always true.

LOGICAL EQUIVALENCE
Here is a rather complicated proposition:
‘It is not the case that both the input file and
the output file are not on the disk.’
The proposition below expresses the same
idea more simply:
‘Either the input file or the output file is on
the disk.’

Two propositions P(p, q, . . .) and Q(p, q,


. . .) are said to be logically equivalent, or
simply equivalent or equal, denoted by
P(p, q, . . .) ≡ Q(p, q, . . .) if they have
identical truth tables

Example : Let p be “Roses are red” and q


be “Violets are blue.”
Let S be the statement:
“It is not true that roses are red and violets
are blue.”
Then S can be written in the form ¬(p ∧ q).
However, as noted above, ¬ (p ∧ q) ≡ ¬p ∨
¬q.
Accordingly, S has the same meaning as the
statement:
“Roses are not red, or violets are not blue.”

Laws of logic
 Occasions often arise in practice
where it is desirable to replace a
logical expression with a simpler
expression that is logically equivalent
 For example, we have seen how
logical expressions representing
propositions can occur in algorithms
and computer programs.
o By writing these expressions as
simply as possible, we can make a
program more efficient and reduce
the chance of error.
 In order to be able to simplify logical
expressions effectively, we need to
establish a list of pairs of expressions
that are logically equivalent.
 We will use the symbol placed
between two expressions to indicate
that they are equivalent.
o A statement of the formP Q
where P and Q are logical
expressions is called a law of
logic.

Laws of logic

 The first two laws in Table allow the


connectives if-then and if and-only-if
to be removed from any expression
containing them.
o The remaining laws involve just
the connectives and, or and not.
o Except for the double negation
law, these laws occur in pairs, in
which the second law in the pair
can be obtained from the first by
interchanging and T with F.
o(Here, T means any true
proposition, and F means any false
proposition.)
oThe second law in each pair is said to
be the dual of the first, and vice versa.
The double negation law is its own
dual.
oThe list of laws in Table is very
comprehensive, and it might
appear rather daunting at first.
oHowever, many of the laws are
obvious after a moment’s thought,
such as the double negation law
(‘It is not the case that it is not
raining’ is a convoluted way of
saying ‘It is raining’),
oand the idempotent laws (‘I am
happy and I am happy’ just means
‘I am happy’).
Example
Use a truth table to verify the
first de Morgan’s law

Solution
Example 2
Use the laws of logic to simplify the
expression:
Solution

Example 3
An algorithm contains the following line:
If not(x > 5 and x<=10) then ..
How could this be written more simply?
Solution
Example
Use the laws of logic to show that
is a tautology
Solution
Example
Determine whether the following
argument is valid:
‘The file is either a binary file or a text
file. If it is a binary file then my
program won’t accept it. My program
will accept the file.
Therefore the file is a text file.’
Solution
oAn argument of this type consists of
some premises (in this example, the
first three sentences), which together
are supposed to imply the conclusion
(the last sentence). The argument
takes the form of the logical
expression:
Logic and Bit Operations
- Computers represent information
using bits.A bit is a symbol with two
possible values, namely,0 (zero) and
1 (one).

- This meaning of the word bit comes


from binary digit, because zeros and
ones are the digits used in binary
representations of numbers.

- A bit can be used to represent a truth


value, because there are two truth
values, namely, true and false

- we will use a 1 bit to represent true


and a 0 bit to represent false. That is,
1 represents T (true), 0 represents F
(false).

- A variable is called a Boolean


variable if its value is either true or
false. Consequently, a Boolean
variable can be represented using a bit
.This can be summarized as follows:
- Computer bit operations correspond
to the logical connectives. By
replacing true by a one and false by a
zero in the truth tables for the
operators ∧, ∨, and ⊕, the tables
shown below for the corresponding
bit operations are obtained.

- We will also use the notation OR,


AND, and XOR for the operators ∨,∧,
and ⊕, as is done in various
programming languages.
Exercise
2. Find the truth table of ¬p ∧ q.
3. Verify that the proposition p ∨¬(p ∧
q) is a tautology
4. Show that the propositions ¬(p ∧ q) and

¬p ∨¬q are logically equivalent.

You might also like