Lecture 03

advertisement
Propositional Logic
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
Today’s Menu
Some Applications of Propositional Logic
•
•
•
•
Translating English to Propositional Logic
Logic Puzzles
Combinatorial Logic Circuits
Boolean Information Retrieval
Propositional Equivalence
• Equivalences
• Key Equivalences
• CNF and DNF
Satisfiability
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
Translating English Sentences
Steps
• Identify atomic propositions and represent using
propositional variables.
• Determine appropriate logical connectives.
Example: Translate the following sentence into
propositional logic:
“You can access the Internet from campus only if you are a
computer science major or you are not a freshman.”
Solution: Let the variables p, q, and r represent:
p : You can access the internet from campus.
q : You are a computer science major.
r : You are a freshman.
p → (q ∨ ¬r )
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
Logic Puzzles
• An island has two kinds of inhabitants, knights, who always tell the truth,
and knaves, who always lie.
• You go to the island and meet A and B.
– A says “B is a knight.”
– B says “The two of us are of opposite types.”
Example: What are the types of A and B?
Solution: Let p and q be the statements that A is a knight and B is a knight,
respectively. Then p represents the proposition that A is a knave and q
that B is a knave.
– If A is a knight, then p is true. Since knights tell the truth, q must also be true.
Then (p ∧  q)∨ ( p ∧ q) would have to be true, but it is not. So, A is not a
knight, and therefore, p must be true.
– If A is a knave, then B must not be a knight since knaves always lie. So, then both
p and q hold since both are knaves.
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
Combinatorial Logic Circuits
input/output signal:
– 0 represents F
– 1 represents T
p1
p2
p3
pm
Tuesday, January 15, 2013
Chittu Tripathy
Logic
Circuit
q1
q2
q3
qn
Lecture 03
Combinatorial Logic Circuits
input/output signal:
p1
p2
p3
– 0 represents F
– 1 represents T
Logic
Circuit
pm
Logic Gates:
¬p
p
NOT
(inverter)
Tuesday, January 15, 2013
qn
p∧q p
q
p
q
AND
p ∨q p
q
OR
Chittu Tripathy
q1
q2
q3
p ⊕q
XOR
Lecture 03
Combinatorial Logic Circuits
input/output signal:
p1
p2
p3
– 0 represents F
– 1 represents T
Logic
Circuit
pm
Logic Gates:
¬p
p
NOT
(inverter)
qn
p∧q p
q
p
q
p ∨q p
q
AND
OR
Two Special Logic Gates:
p
q
¬ (p ∧ q)
NAND = AND followed by NOT
q1
q2
q3
p
q
p ⊕q
XOR
¬ (p ∨q)
NOR = OR followed by NOT
Complex Combinatorial Circuits can be constructed from these gates.
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
Example of Combinatorial Logic Circuit
¬((p ∧ ¬q) ∨ (¬ p ∧ q)) ∧ (p ∨ q)
p ∧ ¬q
p
¬((p ∧ ¬q) ∨ (¬ p ∧ q))
¬p
¬p∧q
q
¬q
p ∨q
¬((p ∧ ¬q) ∨ (¬ p ∧ q)) ∧ (p ∨ q)
How can we show this to be equivalent to
a simple AND gate, that is p ∧ q ?
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
Boolean Information Retrieval
Document 1: The earth is perfectly spherical. It it? No. It is an
oblate spheroid. That is, the earth is slightly flatter at the poles and
slightly more bulging at the equator.
Document 2: Is the cricket ball perfectly spherical? Well, almost,
but has a slightly raised sewn seam. The seam prevents it from being
perfectly spherical. On the other hand, the seam helps with the
swinging of the ball or to produce sideways deflection after pitching.
Document 3: Is the soccer ball perfectly spherical? Well, almost.
Actually, it is a spherical polyhedron.
Query:
(ball AND spherical) AND (bulging OR seam)
Document 1:
Document 2:
Document 3:
Tuesday, January 15, 2013
0
1
1
1
1
1
1
0
0
Chittu Tripathy
0
1
0
Result
0
1
0
Lecture 03
Propositional Equivalence
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
Tautology, Contradiction, Contingency
• A tautology is a proposition which is always TRUE.
– Example: p ∨¬p
• A contradiction is a proposition which is always FALSE.
– Example: p ∧¬p
• A contingency is a proposition which is neither a
tautology nor a contradiction, such as most previous
propositions p we have seen
p
¬p
p ∨¬p
p ∧¬p
T
F
T
F
F
T
T
F
For any contingency p
 p ∨¬p is a tautology
 p ∧¬p is a contradiction
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
Propositional Equivalence
• Two compound propositions p and q are logically
equivalent if p↔q is a tautology.
• In other words, p and q always evaluate to the
same truth value for any truth assignment to the
propositional variables that constitute the
compound propositions p and q.
• We write this as p ⇔ q or p ≡ q .
Example: Show that ¬p ∨ q ≡ p → q ≡ ¬q → ¬p .
Tuesday, January 15, 2013
p
q
¬p
¬q
¬p ∨ q
p→ q
¬q → ¬p
T
T
F
F
T
T
T
T
F
F
T
F
F
F
F
T
T
F
T
T
T
F
F
T
T
T
T
T
Chittu Tripathy
Lecture 03
De Morgan’s Laws
¬(p ∧ q) ≡ ¬p ∨ ¬q
¬(p ∨ q) ≡ ¬p ∧ ¬q
p
q
¬p
¬q
p ∧ q ¬(p ∧q) ¬p ∨¬q
p ∨q
¬(p ∨q)
¬p∧¬q
T
T
F
F
T
F
F
T
F
F
T
F
F
T
F
T
T
T
F
F
F
T
T
F
F
T
T
T
F
F
F
F
T
T
F
T
T
F
T
T
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
Key Logical Equivalences
Identity Laws
Domination Laws
Idempotent laws
Exercise: Prove these
laws using Truth Table.
Double Negation Law
Negation Laws
Commutative Laws
Associative Laws
Distributive Laws
Absorption Laws
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
More Logical Equivalences
The following logical equivalences (Rosen 1.3) are
often useful for solving problems. They can be
proved using Truth Tables. They can use used to
prove more logical equivalences!
Logical Equivalences Involving
Conditional Statements
Tuesday, January 15, 2013
Logical Equivalences Involving
Biconditional Statements
Chittu Tripathy
Lecture 03
Example of Equivalence Proof
Example: Show that
is logically equivalent to
Solution:
Exercise: Show that
¬((p ∧ ¬q) ∨ (¬ p ∧ q)) ∧ (p ∨ q) ≡ p ∧ q .
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
Disjunctive Normal Form (DNF)
A propositional formula is in disjunctive normal form (DNF) if it
consists of a disjunction of (1, … ,n) disjuncts where each disjunct
consists of a conjunction of (1, …, m) atomic formulas or the
negation of an atomic formula.
In other words, a DNF is an OR of ANDs.
Example: (p ∧ ¬q) ∨ (¬ p ∧ q) ∨ (p ∨ q)
(p ∧ q ∧ r) ∨ (¬p ∧ q ∨ ¬r)
(p ∧ (q ∨ r)) ∨ (¬p ∧ q ∨ ¬r)
¬(p ∨ q)
Tuesday, January 15, 2013
Chittu Tripathy
DNF
Not DNF
Lecture 03
Conjunctive Normal Form
A compound proposition is in Conjunctive Normal
Form (CNF) if it is a conjunction of disjunctions.
In other words, a CNF is an AND of ORs.
Example: (p ∨ ¬q) ∧ (¬ p ∨ q) ∧ (p ∨ q)
(p ∨ q ∨ r) ∧ (¬p ∨ q ∨ ¬r)
(p ∨ (q ∧ r)) ∧ (¬p ∨ q ∨ ¬r)
¬(p ∧ q)
Tuesday, January 15, 2013
Chittu Tripathy
CNF
Not CNF
Lecture 03
Proposition to CNF and DNF
Proposition
DNF
⇔
CNF
Every compound proposition
can be rewritten in CNF or DNF.
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
Proposition ⇔ DNF
• Construct the Truth Table for the proposition
• Pick each row that evaluates to T
–If a variable r in this row is T then write it as it; otherwise,
write the negation of it, i.e., ¬r
–OR these written literals (literal = variable or its complement)
Example: Truth Table for
p  q → r
p q r
r
pq
p  q → r
T T T
F
T
F
T T F
T
T
T
T F T
F
T
F
T F F
T
T
T
F T T
F
T
F
F T F
T
T
T
F F T
F
F
T
F F F
T
F
T
Tuesday, January 15, 2013
≡

(pqr)



(pqr)
p  q → r
(pqr)
(pqr)
(pqr)
Chittu Tripathy
Lecture 03
Proposition ⇔ CNF
Express the formula using AND, OR and NOT. To convert
it to CNF move negation inwards and use the distributive
and associative laws.
Example: Convert the following formula to CNF:
(p → q ) (r → p )
Solution:
1. Eliminate implication signs
(p  q)  (r  p)
2. Move negation inwards; eliminate double negation
(p ∧  q)  (r  p)
3. Convert to CNF using associative/distributive laws
(p  r  p) ∧ ( q  r  p)
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
Propositional Satisfiability
• A compound proposition is satisfiable if there exists a truth
assignment to its variables that make it TRUE. When no such
assignments exist, the compound proposition is unsatisfiable.
• A compound proposition is unsatisfiable iff its negation is a
tautology.
Examples: Test if the following propositions are satisfiable.
1
Solution: Satisfiable. Assign T to p, q, and r.
2
Solution: Satisfiable. Assign T to p and F to q.
3
Solution: Not satisfiable. We cannot find a possible truth
assignment to the variables!
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
How Hard is Satisfiablity?
• Satisfiability can be checked using a truth table
• Size of the truth table doubles with each variable
• Therefore, size (#rows) of truth table is exponential in the
number of variables
• In general, no better way is known to test satisfiability efficiently
Million-Dollar Problem: P = NP?
The P=NP? Problem is all about finding an
efficient (polynomial time algorithm) to test
satisfiability.
Tuesday, January 15, 2013
Chittu Tripathy
Lecture 03
Download