propositional logic - duke computer science · propositional variables. •determine appropriate...
Post on 29-May-2020
13 Views
Preview:
TRANSCRIPT
Lecture 03
Propositional Logic
Tuesday, January 15, 2013 Chittu Tripathy
Lecture 03
Today’s Menu
Tuesday, January 15, 2013 Chittu Tripathy
• Translating English to Propositional Logic
• Logic Puzzles
• Combinatorial Logic Circuits
• Boolean Information Retrieval
Some Applications of Propositional Logic
Propositional Equivalence • Equivalences
• Key Equivalences
• CNF and DNF
Satisfiability
Lecture 03
Translating English Sentences
Tuesday, January 15, 2013 Chittu Tripathy
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 )
Lecture 03
Logic Puzzles
Tuesday, January 15, 2013 Chittu Tripathy
• 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.
Lecture 03
Combinatorial Logic Circuits
Tuesday, January 15, 2013 Chittu Tripathy
input/output signal: – 0 represents F
– 1 represents T
Logic Circuit
p1 p2 p3
pm
q1 q2 q3
qn
Lecture 03
Combinatorial Logic Circuits
Tuesday, January 15, 2013 Chittu Tripathy
input/output signal: – 0 represents F
– 1 represents T
Logic Circuit
p1 p2 p3
pm
q1 q2 q3
qn
NOT (inverter)
AND OR XOR
Logic Gates: ¬p p
p
q p ∧ q p
q p ∨q p
q p ⊕q
Lecture 03
Combinatorial Logic Circuits
Tuesday, January 15, 2013 Chittu Tripathy
input/output signal: – 0 represents F
– 1 represents T
Logic Circuit
p1 p2 p3
pm
q1 q2 q3
qn
NOT (inverter)
AND OR XOR
Logic Gates:
Two Special Logic Gates:
NAND = AND followed by NOT NOR = OR followed by NOT
¬p p p
q p ∧ q p
q p ∨q p
q p ⊕q
p
q ¬ (p ∧ q) p
q ¬ (p ∨q)
Complex Combinatorial Circuits can be constructed from these gates.
Lecture 03
Example of Combinatorial Logic Circuit ¬((p ∧ ¬q) ∨ (¬ p ∧ q)) ∧ (p ∨ q)
Tuesday, January 15, 2013 Chittu Tripathy
p
q
¬p
¬q
¬ p ∧ q
¬((p ∧ ¬q) ∨ (¬ p ∧ q))
p ∧ ¬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 ?
Lecture 03
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.
Boolean Information Retrieval
Tuesday, January 15, 2013 Chittu Tripathy
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.
Query:
Document 3: Is the soccer ball perfectly spherical? Well, almost.
Actually, it is a spherical polyhedron.
(ball AND spherical) AND (bulging OR seam)
Document 1:
Document 2:
Document 3:
1 0 1 0
1 1
1 1
0 0
1 0
Result
0 1 0
Lecture 03
Propositional Equivalence
Tuesday, January 15, 2013 Chittu Tripathy
Lecture 03
Tautology, Contradiction, Contingency
Tuesday, January 15, 2013 Chittu Tripathy
• 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
Lecture 03
• 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 .
Propositional Equivalence
Tuesday, January 15, 2013 Chittu Tripathy
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
Example: Show that ¬p ∨ q ≡ p → q ≡ ¬q → ¬p .
Lecture 03
De Morgan’s Laws
Tuesday, January 15, 2013 Chittu Tripathy
¬(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
Lecture 03
Key Logical Equivalences
Tuesday, January 15, 2013 Chittu Tripathy
Identity Laws Domination Laws Idempotent laws Double Negation Law Negation Laws Commutative Laws Associative Laws Distributive Laws Absorption Laws
Exercise: Prove these laws using Truth Table.
Lecture 03
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!
More Logical Equivalences
Tuesday, January 15, 2013 Chittu Tripathy
Logical Equivalences Involving Conditional Statements
Logical Equivalences Involving Biconditional Statements
Lecture 03
Example of Equivalence Proof
Tuesday, January 15, 2013 Chittu Tripathy
Example: Show that
is logically equivalent to
Solution:
¬((p ∧ ¬q) ∨ (¬ p ∧ q)) ∧ (p ∨ q) ≡ p ∧ q . Exercise: Show that
Lecture 03
Disjunctive Normal Form (DNF)
Tuesday, January 15, 2013 Chittu Tripathy
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.
(p ∧ ¬q) ∨ (¬ p ∧ q) ∨ (p ∨ q) (p ∧ q ∧ r) ∨ (¬p ∧ q ∨ ¬r) (p ∧ (q ∨ r)) ∨ (¬p ∧ q ∨ ¬r) ¬(p ∨ q)
Example:
Not DNF
DNF
Lecture 03
Conjunctive Normal Form
Tuesday, January 15, 2013 Chittu Tripathy
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.
(p ∨ ¬q) ∧ (¬ p ∨ q) ∧ (p ∨ q) (p ∨ q ∨ r) ∧ (¬p ∨ q ∨ ¬r) (p ∨ (q ∧ r)) ∧ (¬p ∨ q ∨ ¬r) ¬(p ∧ q)
Example:
Not CNF
CNF
Lecture 03
Proposition to CNF and DNF
Tuesday, January 15, 2013 Chittu Tripathy
⇔
Proposition
CNF DNF
Every compound proposition can be rewritten in CNF or DNF.
Lecture 03
•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)
Proposition ⇔ DNF
Tuesday, January 15, 2013 Chittu Tripathy
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
Truth Table for p q → r Example:
(pqr)
(pqr)
(pqr) (pqr)
(pqr)
p q → r ≡
Lecture 03
Example: Convert the following formula to CNF:
Solution:
1. Eliminate implication signs
2. Move negation inwards; eliminate double negation
3. Convert to CNF using associative/distributive laws
Tuesday, January 15, 2013 Chittu Tripathy
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.
(p → q ) (r → p )
(p q) (r p)
(p ∧ q) (r p)
(p r p) ∧ ( q r p)
Lecture 03
Propositional Satisfiability
Tuesday, January 15, 2013 Chittu Tripathy
• 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.
Solution: Satisfiable. Assign T to p, q, and r.
Solution: Satisfiable. Assign T to p and F to q.
Solution: Not satisfiable. We cannot find a possible truth assignment to the variables!
1
2
3
Lecture 03
How Hard is Satisfiablity?
Tuesday, January 15, 2013 Chittu Tripathy
• 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
The P=NP? Problem is all about finding an efficient (polynomial time algorithm) to test satisfiability.
Million-Dollar Problem: P = NP?
top related