DM Set01 Logic
DM Set01 Logic
Tassos Dimitriou
CpE-203
Discrete Structures
Set 1
Prof. Tassos Dimitriou
Tassos Dimitriou
Outline
Introduction to Logic
Propositions
Variables
Logical operators
Applications of Logic
Predicates and quantifiers
1
1/17/2019
Tassos Dimitriou
Logic
The rules of logic give precise meaning to mathematical
statements. These rules are used to distinguish
between valid and invalid mathematical arguments.
Numerous applications.
These rules are used in the design of computer circuits, the
construction and verification of the correctness of
programs, artificial intelligence, computer programming,
etc.
Logic is based on propositions. A proposition is a statement
that is either true or false (but not both).
Statement: A declarative sentence.
Tassos Dimitriou
2
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
Is this a proposition? no
3
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
Is this a statement? no
It’s a request…
Is this a proposition? no
4
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
Propositional variables
As we have seen in the previous examples, one or more
propositions can be combined to form a single
compound proposition
5
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
6
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
Logical operators: OR
An “or” operation is true if either (at least one) operands are
true
Symbol: or ‘+’ p q pq
T T T
pq = “Today is Friday or T F T
today is my birthday (or F T T
possibly both)” F F F
7
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
8
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
Practice
Write each of these statements in the form “if p, then q” in
English.
a) It snows whenever the wind blows from the northeast.
b) The apple trees will bloom if it stays warm for a week.
c) That the Pistons win the championship implies that they beat the
Lakers.
d) It is necessary to walk 8 miles to get to the top of Long’s Peak.
e) To get tenure as a professor, it is sufficient to be world famous.
f ) If you drive more than 400 miles, you will need to buy gasoline.
g) Your guarantee is good only if you bought your CD player less
than 90 days ago.
h) Jan will go swimming unless the water is too cold.
9
1/17/2019
Tassos Dimitriou
Contrapositive
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.
Tassos Dimitriou
10
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
11
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
12
1/17/2019
Tassos Dimitriou
Translation Example 2
Heard on the radio:
A study showed that there was a correlation between the more
children ate dinners with their families and lower rate of
substance abuse by those children
Tassos Dimitriou
Translation Example 3
You can access the Internet from campus only if you are
a computer science major or you are not a freshman.
a (c f)
You cannot ride the roller coaster if you are under 4 feet
tall unless you are older than 16 years old.
(f o) r
r ( f o)
13
1/17/2019
Tassos Dimitriou
System specs
System specifications should be consistent, that is, they should
not contain conflicting requirements that could be used to derive
a contradiction.
When specifications are not consistent, there would be no way to
develop a system that satisfies all specifications.
Determine whether these system specifications are consistent:
“The diagnostic message is stored in the buffer or it is
retransmitted.”
“The diagnostic message is not stored in the buffer.”
“If the diagnostic message is stored in the buffer, then it is
retransmitted.”
What happens if we add “The diagnostic message is not
retransmitted”?
Tassos Dimitriou
Logic circuits
Propositional logic can be applied to the design of computer
hardware.
A logic circuit (or digital circuit)
receives input signals p1, p2, . . . , pn, each bit is either 0 (off) or 1
(on), and
produces output signals s1, s2, . . . , sn, each a bit.
14
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
Compound statements
We can use the connectives to build compound propositions
involving any number of propositional variables.
We can use truth tables to determine the truth values of these
compound propositions.
Construct the truth table of the compound proposition
(p ∨¬q) → (p ∧ q)
15
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
Examples
Identity law p T p
p T pT
T T T
F T F
16
1/17/2019
Tassos Dimitriou
Examples
Prove De Morgan’s laws shown
alongside:
These laws are very important.
They tell us how to negate
conjunctions and how to negate
disjunction.
Tassos Dimitriou
Examples
Associative law (p q) r p (q r)
17
1/17/2019
Tassos Dimitriou
Logical Equivalences
pTp (p q) r p (q r)
Identity Laws Associative laws
pFp (p q) r p (q r)
pTT p (q r) (p q) (p r)
Domination Law Distributive laws
pFF p (q r) (p q) (p r)
Double p (p q) p
( p) p negation law
Absorption laws
p (p q) p
Definition of Definition of
pq pq Implication p q (p q) (q p) Biconditional
Tassos Dimitriou
(p q) r Definition of implication
18
1/17/2019
Tassos Dimitriou
Example
Show that (p q) (p q) is a Tautology.
(p q) (p q)
(p q) (p q) Implication
( p q) (p q) De Morgan
( p p) ( q q) Commutative, Associative
TT Negation
T
Tassos Dimitriou
Satisfiability
A compound proposition is satisfiable if there is an
assignment of truth values to its variables that makes it
true.
When no such assignments exists, that is, when the
compound proposition is false for all assignments of truth
values to its variables, the compound proposition is
unsatisfiable.
19
1/17/2019
Tassos Dimitriou
Satisfiability (cont.)
Determine whether each of the following compound
propositions is satisfiable. Do not use truth tables
Tassos Dimitriou
Example
At a trial:
Bill says: “Sue is guilty and Fred is innocent.”
Sue says: “If Bill is guilty, then so is Fred.”
Fred says: “I am innocent, but at least one of the others is guilty.”
20
1/17/2019
Tassos Dimitriou
Example (cnt)
(s f) (b f) (f (b s))
LHS ( s f) (b f) (f ( b s))
(( s f) (f ( b s))) (b f)
( s f ( b s)) (b f)
(( s f b) ( s f)) (b f)
( s f) (b f)
( s f b) s f f)
( s f b) F
sfb
Tassos Dimitriou
Suppose we know
“Every computer connected to the university network is
functioning properly.”
No rule of propositional logic allow us to conclude the truth of
the statement
“CpE server 3 is functioning properly”
21
1/17/2019
Tassos Dimitriou
Predicates
Statements involving variables, such as
“x > 3,” “x = y + 3,” “x + y = z,” and
“computer x is under attack by an intruder,”
are often found in mathematical assertions, in computer
programs, and in system specifications.
These statements are neither true nor false when the values
of the variables are not specified.
Tassos Dimitriou
Predicates
Consider the statement “x is greater than 3”
x: subject
“is greater than 3”: predicate
P(x): propositional function P at x
P(x) = x + 5 > 10
variable predicate
22
1/17/2019
Tassos Dimitriou
Quantifiers (cont.)
Let P(x) denote the statement “x > 3.” What are the truth
values of P(4) and P(2)?
Tassos Dimitriou
Quantifiers
Quantification is another way to create a proposition from a
propositional function.
Quantification expresses the extent to which a predicate is true
over a range of elements.
In English, the words all, some, many, none, and few are used in
quantifications.
23
1/17/2019
Tassos Dimitriou
Universal quantifiers 1
The universal quantification of P(x) is the statement “P(x) for
all values of x in the domain.”
Represented by an upside-down A:
It means “for all”
Let P(x) = x+1 > x
Tassos Dimitriou
Universal quantifiers 2
But is that always true?
x P(x)
Let x = the character ‘a’
Is ‘a’+1 > ‘a’?
Let x = Kuwait
Is Kuwait+1 > Kuwait?
24
1/17/2019
Tassos Dimitriou
Universal quantifiers 3
Let the universe be the real numbers.
Tassos Dimitriou
Universal quantification 4
Given some propositional function P(x) and values in the
universe x1 … xn
25
1/17/2019
Tassos Dimitriou
Existential quantification 1
Represented by an backwards E:
It means “there exists”
Let P(x) = x+1 > x
Tassos Dimitriou
Existential quantification 2
Note that you still have to specify your universe/domain
Let P(x) denote the statement “x > 3.” What is the truth value
of the quantification ∃xP(x), where the domain consists of all
real numbers?
26
1/17/2019
Tassos Dimitriou
Existential quantification 3
Let P(x) = x+1 > x
There is a numerical value for which x+1>x
In fact, it’s true for all of the values of x!
Thus, x P(x) is true
Tassos Dimitriou
Existential quantification 4
Given some propositional function P(x) and values in the
universe x1 .. xn, what “x P(x)” is a shorthand for?
27
1/17/2019
Tassos Dimitriou
Quantifiers – Summary
It is sometimes helpful to think in terms of looping and
searching when determining the truth value of a quantification.
Suppose that there are n objects in the domain for the
variable x.
To determine whether ∀xP(x) is true, we can loop through all n
values of x to see whether P(x) is always true.
If we encounter a value x for which P(x) is false, then we have
shown that ∀xP(x) is false. Otherwise, ∀xP(x) is true.
To see whether ∃xP(x) is true, we loop through the n values of x
searching for a value for which P(x) is true.
If we find one, then ∃xP(x) is true. If we never find such an x, then
we have determined that ∃xP(x) is false.
Does not work for infinite number of objects n
Tassos Dimitriou
Binding variables
Let P(x,y) be x > y
Consider: x P(x,y)
Is this a proposition? Why?
What is y?
If it’s 5, then x P(x,y) is false
If it’s x-1, then x P(x,y) is true
28
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
Negating quantifications
Consider the statement:
All students in this class have red hair
29
1/17/2019
Tassos Dimitriou
Negating quantifications 2
Consider the statement:
There is a student in this class with red hair
Tassos Dimitriou
30
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
Order matters
Let Q(x, y) denote “x + y = 0.”
What are the truth values of the quantifications ∃y∀xQ(x, y) and
∀x∃yQ(x, y), where the domain for all variables consists of all
real numbers?
31
1/17/2019
Tassos Dimitriou
32