Proposition A proposition is a statement that is either true or false, but not both. • Clemson will defeat Georgia in football this fall. • 1+1 = 2 • 3+1 = 5 • What will be my grade in CPSC 2070? Propositional Logic CPSC 2070 Discrete Structures Rosen (6th Ed.) 1.1, 1.2 Definition 1. Negation of p LOGICAL We can define operations on propositions! Let p be a proposition. The statement “It is not the case that p” is also a proposition, called the “negation of p” or ¬p (read “not p”) p = The sky is blue. ¬p = It is not the case that the sky is blue. Table 1. The Truth Table for the Negation of a Proposition p ¬p T F F T ¬p = The sky is not blue. Definition 2. Conjunction of p and q Let p and q be propositions. The proposition “p and q,” denoted by p∧q is true when both p and q are true and is false otherwise. This is called the conjunction of p and q. Table 2. The Truth Table for the Conjunction of two propositions p q p∧q T T F F T F T F T F F F Definition 3. Disjunction of p and q Table 3. The Truth Table for the Disjunction of two propositions p q p∨q T T F F T F T F T T T F Let p and q be propositions. The proposition “p or q,” denoted by p∨q, is the proposition that is false when p and q are both false and true otherwise. 1 Definition 4. Exclusive or of p and q Table 4. The Truth Table for the Exclusive OR of two propositions p q p⊕q T T F F T F T F F T T F 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. Definition 5. Implication p→q Let p and q be propositions. The implication p→q is the proposition that is false when p is true and q is false, and true otherwise. In this implication p is called the hypothesis (or antecedent or premise) and q is called the conclusion (or consequence). Politician Example Implications • • • • • • • If p, then q p implies q if p,q p is sufficient for q q if p q whenever p q is necessary for p • Not the same as the if-then construct used in programming languages such as If p then S p q p↔q T T F F T F T F T F F T Let p and q be propositions. The biconditional p↔q is the proposition that is true when p and q have the same truth values and is false otherwise. “p if and only if q, p is necessary and sufficient for q” p q p→q T T F F T F T F T F T T Related Implications Converse of p → q is the proposition q→p Contrapositive of p → q is the proposition ¬q → ¬p Inverse of p → q is the proposition ¬p → ¬q Definition 6. Biconditional Table 6. The Truth Table for the biconditional p↔q. Table 5. The Truth Table for the Implication of p→q. Compound Propositions We can also combine operations to create compound propositions such as: Don’t try to do it Test all possible ¬(p ∨ q) ∧ q all in your head! combinations of T/ F p q (p ∨ q) ¬(p ∨ q) ¬(p ∨ q) ∧ q T T T F F T F T F F F T T F F F F F T F 2 Special Types of Compound Propositions • Contradiction: Compound proposition that is always false regardless of the truth values of the propositions in it. p ∧ ¬p is a contradiction • Tautology: compound proposition that is always true regardless of the truth values of the propositions in it. p ∨ ¬p is a tautology Practice with English Sentences p: You learn the simple things well. q: The difficult things become easy. • The difficult things become easy but you did not learn the simple things well. • You learn the simple things well but the difficult things did not become easy. • You do not learn the simple things well. • If you learn the simple things well then the difficult things become easy. • If you do not learn the simple things well, then the difficult things will not become easy. Practice with English Sentences p: You learn the simple things well. q: The difficult things become easy. • You do not learn the simple things well. ¬p • If you learn the simple things well then the difficult things become easy. p→q • If you do not learn the simple things well, then the difficult things will not become easy. • The difficult things become easy but you did not learn the simple things well. q ∧ ¬p • You learn the simple things well but the difficult things did not become easy. Some Applications of Propositional Logic p ∧ ¬q ¬p → ¬q Truth Table Puzzle Steve would like to determine the relative salaries of three coworkers using two facts: • If Fred is not the highest paid of the three, then Janice is. • If Janice is not the lowest paid, then Maggie is paid the most. Who is paid the most and who is paid the least? p : Janice is paid the most. q: Maggie is paid the most. r: Fred is paid the most. s: Janice is paid the least. p T F F F F q F T F T F r F F T F T s F T T F F ¬r→p T F T F T If Janice is not the lowest If Fred is not the paid, then Maggie is paid highest paid of the the most. three, then Janice is. ¬s →q (¬r→p)∧ (¬s→q) F F T F T T T F F F Fred, Maggie, Janice 3 Knights and Knaves Puzzles Let a be the statement that “A is a Knight” and b be the statement that “B is a Knight.” A says “B and I are both Knights.” If A is a Knight then a is true and the statement (a∧b) is true. If A is a Knave, then a is false and the statement is false. These are the two cases that are “true” in that they are possible solutions to the puzzle. We can code this with the biconditional operator ↔. (Recall that p↔q is true when both propositions are true or both propositions are false.) On a remote island there live Knights and Knaves. Knights always tell the truth and Knaves always lie. B says “A is a Knave.” Using the same logic add b ↔ ¬a to the table. You meet two people on the island—A and B. A says: “B and I are both Knights.” B says: “A is a Knave.” Determine, if possible, which group A and B belong to. A says “At least one of us is a Knave” and B says nothing. a (A is a Knight) b (B is a Knight) ¬a ∨ ¬b a ↔ (¬a ∨ ¬b) T T F F T F T F F T T T F T F F a (A is a Knight) b (B is a Knight) (a∧b) a ↔ (a∧b) b ↔ ¬a T T T T F T F F F T F T F T T F F F T F The Hat Puzzle Three students who made an “A” in CPSC 2070 are told to stand in a straight line, one in front of the other. A hat is put on each of their heads. They are told that each of these hats was selected from a group of five hats: two black hats and three white hats. The first student, standing at the front of the line, can’t see either of the students behind her or their hats. The second student, in the middle, can see only the first student and her hat. The last student, at the rear, can see both other students and their hats. None of them can see the hat on their own head. They are asked to deduce its color. The last student in line is asked if he knows the color of his hat and says he cannot be sure. The second student in line is asked if he knows the color of his hat and says he cannot be sure. The student at the front of the line then says: “My hat is white.” She is correct. How did she come to this conclusion? Bit Operations Last Second First W W W W W B W W B B W B B B W W W B B B W A computer bit has two possible values: 0 (false) and 1 (true). A variable is called a Boolean variable is its value is either true or false. Bit operations correspond to the logical connectives: ∨ OR ∧ AND ⊕ XOR Information can be represented by bit strings, which are sequences of zeroes and ones, and manipulated by operations on the bit strings. 4 Truth tables for the bit operations OR, AND, and XOR ∨ 0 0 0 1 1 1 1 1 ∧ 0 0 0 0 1 0 1 ⊕ 0 0 0 1 1 1 0 1 1 Binary Math Review Decimal has digits 0-9 0 0 1 3 ___ ___ ___ ___ 3 2 1 10 10 10 100 0+1 = 1 1+0 = 1 1+1 = 10 10 + 1 = 11 11 + 1 = 100 Binary has digits 0-1 1 1 0 1 ___ ___ ___ ___ 3 2 1 2 2 2 20 Program to add 3 binary digits p q r Output 1 Output 2 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 Output 1 = (p∧q) ∨ (p∧r) ∨ (q∧r) 1 Output 2 = p ⊕ q ⊕ r Logically Equivalent • Compound propositions P and Q are logically equivalent if P↔Q is a tautology. In other words, P and Q have the same truth values for all combinations of truth values of simple propositions. • This is denoted: P⇔Q Full Adder: Computers contain switches (logic gates) corresponding to our logic operations Example: DeMorgans • Prove that ¬(p∨q) ⇔ (¬p ∧ ¬q) p q (p∨q) TT TF FT FF T F F F F T F F T F T F F T T T F T F T ¬(p∨q) ¬p ¬q (¬p ∧ ¬q) Example: Distribution Prove that: p ∨ (q ∧ r) ⇔ (p ∨ q) ∧ (p ∨ r) p T T T T F F F F q T T F F T T F F r T F T F T F T F q∧r p∨(q∧r) p∨q T T T F T T F T T F T T T T T F F T F F F F F F p∨r T T T T T F T F (p∨q)∧(p∨r) T T T T T F F F 5 Prove: p↔q⇔(p→q) ∧ (q→p) pq TT TF FT FF p↔q T F F T p→q q→p T T F T T F T T (p→q)∧(q→p) T F F T We call this biconditional equivalence. List of Logical Equivalences Table 6 in Section 1.2 p∧T ⇔ p; p∨F ⇔ p Identity Laws p∨T ⇔ T; p∧F ⇔ F Domination Laws p∨p ⇔ p; p∧p ⇔ p Idempotent Laws ¬(¬p) ⇔ p Double Negation Law p∨q ⇔ q∨p; p∧q ⇔ q∧p Commutative Laws (p∨q)∨ r ⇔ p∨ (q∨r); (p∧q) ∧ r ⇔ p ∧ (q∧r) Associative Laws List of Equivalences p∨(q∧r) ⇔ (p∨q)∧(p∨r) p∧(q∨r) ⇔ (p∧q)∨(p∧r) Distributive Laws ¬(p∨q)⇔(¬p ∧ ¬q) ¬(p∧q)⇔(¬p ∨ ¬q) De Morgan’s Laws p ∨ (p∧q) ⇔ p p ∧ (p∨q) ⇔ p Absorption Laws p ∨ ¬p ⇔ T p ∧ ¬p ⇔ F Negation Laws (p→q) ⇔ (¬p ∨ q) Implication Equivalence Or Tautology; And Contradiction 6