Logic For CS 2
Logic For CS 2
Logic For CS 2
• Example: Find the bitwise OR, bitwise AND, and bitwise XOR of the bit
string 01 1011 0110 and 11 0001 1101.
Solution:
01 1011 0110
11 0001 1101
-------------------
11 1011 1111 bitwise OR
01 0001 0100 bitwise AND
10 1010 1011 bitwise XOR
2
Well Formed Formula (WFF)
A wff is defined as follows:
i.If p is a propositional variable then, it is a wff.
ii.If p is a propositional variable then ¬p is a wff.
iii.If p and q are wffs then (p V q), (p Λ q), (p → q),
(p ↔ q) are wffs.
iv.A string of symbols is a wff if and only if it is
obtained by a finite number of applications of i-iii.
3
Propositional Equivalences
DEFINITION 8
A compound proposition that is always true, no matter what the truth
values of the propositions that occurs in it, is called a tautology. A
compound proposition that is always false is called a contradiction. A
compound proposition that is neither a tautology or a contradiction is
called a contingency.
T F T F
F T T F
4
Propositional Equivalences
DEFINITION 9
The compound propositions p and q are called logically equivalent if p ↔
q is a tautology. The notation p ≡ q denotes that p and q are logically
equivalent.
• Compound propositions that have the same truth values in all possible
cases are called logically equivalent.
• Example: Show that ¬p ν q and p → q are logically equivalent.
6
Propositional Equivalences
Constructing New Logical Equivalences
• Example: Show that ¬(p → q ) and p Λ ¬q are logically equivalent.
Solution:
¬(p → q ) ≡ ¬(¬p ν q)
≡ ¬(¬p) Λ ¬q by the second De Morgan law
≡ p Λ ¬q by the double negation law
• Example: Show that (p Λ q) → (p ν q) is a tautology.
Solution: To show that this statement is a tautology, we will use logical
equivalences to demonstrate that it is logically equivalent to T.
(p Λ q) → (p ν q) ≡ ¬(p Λ q) ν (p ν q)
≡ (¬ p ν ¬q) ν (p ν q) by the first De Morgan law
≡ (¬ p ν p) ν (¬ q ν q) by the associative and
communicative law for disjunction
≡TνT
≡T
• Note: The above examples can also be done using truth tables.
7
Exercise
Explain, without using a truth table, why (p ∨ q
∨ r) ∧ ( ¬ p ∨ ¬ q ∨ ¬ r) is true when at least
one of p, q, and r is true and at least one is false,
but is false when all three variables have the
same truth value.
8
Solution
The first clause (p V q V r) is true if and only if at least
one of p, q, and r is true. The second clause ( ¬ p V ¬
q V ¬ r) is true if and only if at least one of the three
variables is false. Therefore both clauses are true, and
therefore the entire statement is true, if and only if
there is at least one T and one F among the truth
values of the variables, in other words, that they don't
all have the same truth value.
9
Exercise-1
“You cannot ride the roller coaster if you are under 4 feet
tall unless you are older than 16 years old.”
Solution: Let q, r, and s represent “You can ride the roller coaster,”
“You are under 4 feet tall,” and “You are older than
16 years old.” The sentence can be translated into:
(r Λ ¬ s) → ¬q.
10
Exercise-2
• How can this English sentence be translated into a logical expression?
“You can access the Internet from campus only if you are a
computer science major or you are not a freshman.”
Solution: Let a, c, and f represent “You can access the Internet from
campus,” “You are a computer science major,” and “You are
a freshman.” The sentence can be translated into:
a → (c V ¬f).
11
Exercise-3
Let p and q be the propositions “Swimming at the
New Jersey shore is allowed” and “Sharks have
been spotted near the shore,” respectively.
Express each of these compound propositions as
an English sentence.
a) ¬ q b) p ∧ q c) ¬ p ∨ q
d) p → ¬ q e) ¬ q → p f) ¬p→¬q
g) p ↔ ¬ q h) ¬ p ∧ (p∨ ¬ q)
12
Exercise-4
Construct a truth table for each of these
compound propositions.
a) (p ∨ q) → (p ⊕ q) b) (p ⊕ q) → (p ∧ q)
c) (p ∨ q) ⊕ (p ∧ q) d) (p ↔ q) ⊕ ( ¬ p ↔ q)
e) (p ↔ q) ⊕ ( ¬ p ↔ ¬ r)
f ) (p ⊕ q) → (p ⊕ ¬ q)
13
Exercise-5
A father tells his two children, a boy and a girl, to play in their
backyard without getting dirty. However, while playing, both
children get mud on their foreheads. When the children stop
playing, the father says “At least one of you has a muddy
forehead,” and then asks the children to answer “Yes” or “No”
to the question: “Do you know whether you have a muddy
forehead?”
The father asks this question twice. What will the children
answer each time this question is asked, assuming that a child
can see whether his or her sibling has a muddy forehead, but
cannot see his or her own forehead? Assume that both
children are honest and that the children answer each
question simultaneously.
14
Exercise-6
In an island that has two kinds of inhabitants,
knights, who always tell the truth, and their
opposites, knaves, who always lie.
You encounter two people A and B. What are A
and B if A says “B is a knight” and B says “The
two of us are opposite types?”
15