1 Logic Theory Part1
1 Logic Theory Part1
1
What is Discrete Structure?
Discrete Objects
Separated from each other (Opposite of continuous)
e.g., integers, people, house,
Vs. Continuous objects: e.g., real number
Discrete Structures
The abstract mathematical structures used to represent
discrete objects and relationships between the objects
e.g. sets, relations, graphs
2
Why do we study Discrete Structures?
3
1.1 Propositional Logic
•Introduction
•Propositions
•Propositional Logic
• Negation
• Connectives ( conjunction – disjunction – exclusive OR)
• Conditional statements (implication)
• Converse, Contrapositive and Inverse
• Biconditional
•Truth tables of Compound Propositions
•Precedence of Logic Operators
4
•Logic and Bit Operations
Introduction
The rules of logic are used to distinguish between
valid and invalid mathematical arguments.
Logic has many applications to computer science.
Ex:
Computer circuits.
Construction of computer programs.
5
Propositions
The basic building blocks of logic.
It is a declarative sentence that is either True or
False, but not both.
Example 1 Example 2
1. Riyadh is the capital of 1. What time is it?
Saudi Arabia. 2. Read this
2. Cairo is the capital of carefully.
Lebanon. 3. x+1=2
3. 1+1=2 4. x+y=z
4. 2+2=3
All declarative sentences are Not propositions
propositions not declarative sentences 1+2
T–F–T–F neither true or nor false 3+4
6
Propositions
We use letters to denote propositional variables that
is used to represent propositions, just as letters used
to denote numerical variables.
The conventional letters used for propositions
variables are p, q, r, s…
The truth value if the proposition is true T
The truth value if the proposition is false F
The area of logic that deals with proposition is
called the proposition calculus or propositional
logic.
7
Propositions
There are a methods for producing new
propositions from those what we have.
Many mathematical statement are constructed by
combining one or more propositions (compound
propositions) using logical operators.
8
Negation of a proposition
Definition1 :
Let p be a proposition. The negation of p, denoted by
p, is the statement “it is not the case that p”.
The proposition p is read “NOT p”
Negation construct a new proposition from a
single existing proposition.
The truth table for the negation of a proposition.
p p
Notice that p is a T F
proposition! F T
9
Negation of a proposition
Example 3:
Find the negation of the proposition
“Sara’s pc runs Linux” and express this in simple
English.
Solution:
Negation is: “it is not the case that Sara’s pc runs
Linux”
More simply: “Sara’s pc does not run Linux”
10
Negation of a proposition
Example 4:
Find the negation of the proposition
“Ahmad’s smart phone has at least 32 GB of memory” and
express this in simple English.
Solution:
Negation is: “Ahmad’s smart phone does not have at least32
GB of memory”
More simply: “Ahmad’s smart phone has less than 32 GB of
memory”
11
Conjunction of propositions
Definition2 :
Let p and q be propositions. The conjunction of p
and q, denoted by pq, is the proposition “p and
q”. The conjunction pq is true when both p and q
are true, and is false otherwise.
The truth table for the conjunction of two
proposition.
pq q p
Notice that conjunction T T T
can be between two or F F T
more propositions
F T F
F F F
12
Conjunction of propositions
Example 5:
Find the conjunction of the propositions p and q,
where p is the proposition “Ahmad’s pc has more than 16
GB free hard disk space”
and q is the proposition “The processor in Ahmad’s pc runs
faster than 1 GHz” express this in simple English.
Solution:
Ahmad’s pc has more than 16 GB free hard disk space and The
processor in Ahmad’s pc runs faster than 1 GHz.
Solution:
Ahmad’s pc has more than 16 GB free hard disk space orThe
processor in Ahmad’s pc runs faster than 1 GHz.
When it will be true? False?
15
Exclusive-OR of propositions
Definition4:
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.
The truth table for the exclusive or of two
proposition.
p⊕q q p
F T T
Notice it can be between
T F T
two or more propositions
T T F
16 F F F
Conditional Statement (Implication)
Definition5:
Let p and q be propositions. The conditional statement
(implication) p q is the proposition “if p, then q”. The
conditional statement p q is false when p is true and q is
false, otherwise true.
In the conditional statement p q, p is called the
hypothesis or (antecedent or premise) and q is called the
conclusion or (consequence).
Comes in format:
If p, then q
If p, q
p is sufficient for q
p implies q
…
you will find rest of them in book. Look at them!
17
Conditional Statement (Implication)
The truth table for the implication of two proposition.
pq q p
T T T
F F T
T T F
Ex: T F F
“If you get 100% on the final, then you will get an A”.
Hypothesis Conclusion
18
Conditional Statement (Implication)
Example:
Hypothesis Conclusion
Solution:
If Maria learns discrete mathematics, then she will find job.
Maria will find job when she learns discrete mathematics.
Rest example in book page 7
When it will be true? False?
20
Converse, Contrapositive and Inverse
Converse: q p is converse of p q.
Ex.: p q: “If it is noon, then I am hungry.”
q p: “If I am hungry, then it is noon.”
Contrapositive: q p is contapositive of p q.
Ex.: q p: “If I am not hungry, then it is
not noon.”
Inverse: p q is inverse of p q.
Ex.: p q: “If it is not noon, then I am not
hungry.”
See
example
p q has same truth values as q p 7
21
Biconditional Statement
Definition6:
Let p and q be two propositions. The biconditional
statement (bi-implication) 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,
otherwise false.
It corresponds to English “p if and only if q”.
The truth table of biconditional p↔q q p
T T T
F F T
F T F
T F F
22
Biconditional Statement
Example10:
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”
True if p and q both true or both false
False otherwise
23
Implicit Biconditional Statement
Not always explicit in natural language.
Often expressed using an “if, then” or “only, if”
Converse is implied but not stated.
Ex:
“if you finish your meal, then you can have dessert”
Means
“You can have dessert if and only if you finish your
meal”
24
Truth Table of Compound Proposition
Used to build up complicated compound positions involving
any numbers of propositional variables.
Construct truth table for (p q) → (p q).
(p q) → (p q) p q p q q q p
F F T T F F
F F T T F T
T F F F T F
T T T F T T
Q3: Construct truth table for
(p q) ↔ (p q). of raws = 2 # of variable #
25
(p ⊕ q) → (p ⊕ q).
Precedence
Precedence of Logical Operators:
Precedence Operator
1 ¬
2 Λ
3 ν
4 →
5 ↔
26
Propositional Logic – Translating English
Sentences
The sentence “The automated reply cannot be sent
when the file system is full” can be translated as
q → p
where p: “The automated reply can be sent ”
q: “The file system is full”
The sentence “You cannot drive a car if you are
under 4 feet tall unless you are older than 16 years
old” can be translated as
(q r) → p
where p: “You can drive a car ”
q: “You are under 4 feet tall ”
r: “You are older than 16 years old”
0 0 0 0 0
1 0 1 1 0
1 0 1 0 1
0 1 1 1 1
Example 13
Find bitwise OR, AND, and XOR of the bit strings:
0110110110 and 1100011101
30