Propositional Logic Dr. Yasir Ali • Formal or propositional logic was first developed by the ancient Greeks, who wanted to be able to reason carefully about statements in natural language. • Logical reasoning is difficult and unreliable when using a natural language like Urdu (or English!). • Suppose a friend says ‘The sun is shining and I feel happy’. • ‘Cats are furry and elephants are heavy’. • The word and has several subtly different meanings, and we choose the appropriate meaning using our knowledge of the world. • There is no way to solve all the ambiguities of English. • Instead of attempting the impossible we need to separate the logical structure of an argument from all the connotations of the English. Proposition A proposition is a declarative sentence (that is, a sentence that declares a fact) that is either true or false, but not both. Proposition EXAMPLE : Consider the following sentences. 1. Chocolate cakes are loaded with calories. 2. Disprene helps relieve Headache. 3. Political candidates always tell the complete truth. 4. Shahid Afridi plays cricket. 5. It is Thursday today. Propositions 1 , 2 and 4 are true, whereas 3 is false. What about 5? All are declarative sentences with a truth value and so are propositions. Propositions are also called Statements. EXAMPLE : Consider the following sentences. 1. Where is the book? 2. Let’s go to a movie tonight. 3. I suggest you get contact lenses. 4. Turn off the TV right now. 5. Fantastic! 6. x + 1 = 2. 1 is a question, 2 is a proposal, 3 is a suggestion, 4 is a command, 5 is an exclamation. Sentences 1-5 are not declarative sentences. Sentences 6 is neither true nor false. So all of the above sentences are not propositions. Representation of a proposition • The conventional letters used for propositional variables are p, q, r , s,… • The truth value of a proposition is true, denoted by T, if it is a true proposition and • The truth value of a proposition is false, denoted by F, if it is a false proposition. 1. Washington, D.C., is the capital of the United States of America. Truth value T 2. It is raining outside. Truth value ? 3. Karachi is the smallest city of Pakistan. Truth value F 4. 1 + 1 = 2. Truth value T 5. 2 + 2 = 3. Truth value F 6. It is Wednesday today. Truth value F Compound Propositions Many mathematical statements are constructed by combining one or more propositions. New propositions, called compound propositions, are formed from existing propositions using logical operators or Connectives. Negation Let p be a proposition. The negation of p, denoted by ¬p, is the statement “It is not the case that p.” The proposition ¬p is read “not p”. The truth value of the negation of p, ¬p, is the opposite of the truth value of p. Examples: p=The sun is shining. q= I feel happy. r=Cats are furry. s=Elephants are heavy. Negation: ¬ p=The sun is not shining. ¬ q=I don’t feel happy. / I feel sad. ¬ r=Cats are not furry. ¬ s=Elephants are not heavy / Elephants are light. Truth Table for Negation p ¬p T F F T • Above Table displays the truth table for the negation of a proposition p. • This table has a row for each of the two possible truth values of a proposition p. Each row shows the truth value of ¬p corresponding to the truth value of p for this row. Conjunction / and Let p and q be propositions. The conjunction of p and q, denoted by p ∧ q, is the proposition “p and q.” The conjunction p ∧ q is true when both p and q are true and is false otherwise. Examples: p=The sun is shining. q= I feel happy. r=Cats are furry. s=Elephants are heavy. p ∧ q=The sun is shining and I feel happy. r ∧ s=Cats are furry and elephants are heavy. Truth Table for conjunction p q p∧q T T T T F F F T F F F F Disjunction/ or Let p and q be propositions. The disjunction of p and q, denoted by p ∨ q, is the proposition “p or q.” The disjunction p ∨ q is false when both p and q are false and is true otherwise. Examples: p=The sun is shining. q= I feel happy. r=Cats are furry. s=Elephants are heavy. p v q=The sun is shining or I feel happy. r v s=Cats are furry or elephants are heavy. Truth Table for disjunction p q pvq T T T T F T F T T F F F Exclusive OR Let p and q be propositions. The Exclusive OR of p and q, denoted by p ⊕ q, is the proposition “p or q (but not both)”. This proposition is true when p is true and q is false, and when p is false and q is true. It is false when both p and q are false and when both are true. Examples: 1. Tom is a boy or a girl. 2. You may take either tea or Coffee. Truth Table for Exclusive OR p q p⊕q T T F T F T F T T F F F • p but q means p and q • neither p nor q means ¬ p and ¬ q. Write each of the following sentences symbolically, letting h = “John is healthy” and w = “John is wealthy.” 1. John is not healthy but he is wealthy. 2. John is neither healthy nor wealthy. Solution: 1. The given sentence is equivalent to “John is not healthy and he is wealthy,” which can be written symbolically as ∼h ∧ w. 2. John is neither healthy nor wealthy means that John is not healthy and he is not wealthy as well. Therefore, the given sentence can be written symbolically as ∼h ∧ ∼w. The notation for inequalities involves and and or statements. For instance, if x, a, and b are particular real numbers, then x ≤ a means x < a or x = a a ≤ x ≤ b means a ≤ x and x ≤ b. Example: Suppose x is a particular real number. Let p, q, and r symbolize “3 < x,” “x < 5,” and “x = 5,” respectively. Write the following inequalities symbolically: 1. x ≤ 5 2. 3 < x < 5 3. 3 < x ≤ 5 Construct a truth table for the statement form (p ∧ q) ∨ ¬ r . p q r p∧q ¬r (p ∧ q) ∨ ¬ r Construct a truth table for the statement form (p ∧ q) ∨ ¬ r . p q r T T T p∧q ¬r (p ∧ q) ∨ ¬ r Construct a truth table for the statement form (p ∧ q) ∨ ¬ r . p q r T T T T T F p∧q ¬r (p ∧ q) ∨ ¬ r Construct a truth table for the statement form (p ∧ q) ∨ ¬ r . p q r T T T T T F T F T p∧q ¬r (p ∧ q) ∨ ¬ r Construct a truth table for the statement form (p ∧ q) ∨ ¬ r . p q r T T T T T F T F T F T T p∧q ¬r (p ∧ q) ∨ ¬ r Construct a truth table for the statement form (p ∧ q) ∨ ¬ r . p q r T T T T T F T F T F T T T F F p∧q ¬r (p ∧ q) ∨ ¬ r Construct a truth table for the statement form (p ∧ q) ∨ ¬ r . p q r T T T T T F T F T F T T T F F F T F p∧q ¬r (p ∧ q) ∨ ¬ r Construct a truth table for the statement form (p ∧ q) ∨ ¬ r . p q r T T T T T F T F T F T T T F F F T F F F T p∧q ¬r (p ∧ q) ∨ ¬ r Construct a truth table for the statement form (p ∧ q) ∨ ¬ r . p q r T T T T T F T F T F T T T F F F T F F F T F F F p∧q ¬r (p ∧ q) ∨ ¬ r Construct a truth table for the statement form (p ∧ q) ∨ ¬ r . p q r p∧q T T T T T T F T T F T F F T T F T F F F F T F F F F T F F F F F ¬r (p ∧ q) ∨ ¬ r Construct a truth table for the statement form (p ∧ q) ∨ ¬ r . p q r p∧q ¬r T T T T F T T F T T T F T F F F T T F F T F F F T F T F F T F F T F F F F F F T (p ∧ q) ∨ ¬ r Construct a truth table for the statement form (p ∧ q) ∨ ¬ r . p q r p∧q ¬r T T T T F T T F T T T F T F F F T T F F T F F F T F T F F T F F T F F F F F F T (p ∧ q) ∨ ¬ r Construct a truth table for the statement form (p ∧ q) ∨ ¬ r . p q r p∧q ¬r (p ∧ q) ∨ ¬ r T T T T F T T T F T T T T F T F F F F T T F F F T F F F T T F T F F T T F F T F F F F F F F T T Construct a truth table for the statement form (p ∧ q) ∨ ¬ r . p q r p∧q ¬r (p ∧ q) ∨ ¬ r T T T T F T T T F T T T T F T F F F F T T F F F T F F F T T F T F F T T F F T F F F F F F F T T Another description of Exclusive or (XOR). Construct the truth table of (p ∨ q) ∧ ¬ (p ∧ q). (p or q but not p and q) p q p v q p ∧ q ¬(p ∧ q) (p ∨ q) ∧ ¬ (p ∧ q) T T T T F F T F T F T T F T T F T T F F F F T F Conditional Statements Let p and q be propositions. The conditional statement p → q is the proposition “if p, then q.” The conditional statement p → q is false when p is true and q is false, and true otherwise. p is called the hypothesis (or antecedent or premise) and q is called the conclusion (or consequence). Truth Table for Conditional Statements p q p→q T T T T F T F T F F F T • s=It is sunny today. • p= There will be a picnic. • s → p: If it is sunny today, then there will be a picnic. There is a subtle but crucial difference between → and the corresponding English sentences. • m=The moon orbits the earth. • h=The sun is hot. • m → h If the moon orbits the earth, then the sun is hot. Logical implication says nothing about cause-and-effect relationships. • c=The sun is cold. • g= The moon is made of green cheese. • c→ g If the sun is cold, then the moon is made of green cheese. Here, c and g are both false, but the definition says that c → g is true. Why should the English translation of c → g be true? Suppose your friend claims that ‘Fifty people came to my party last night.’ but you’re sure there were only twenty.. You might retort.. ‘If fifty people went to your party, then I’m the king of China.’ English sentences contain all sorts of connotations, but logical propositions mean nothing more than what the defining truth tables say. The truth table for → is just a definition. It is meaningless to argue about whether the definition given above is ‘correct’; definitions aren’t either right or wrong, they are just definitions. Consider another statement: “If you get 100% on the final, then you will get an A.” So what do you say about the statement: “If 0=1, then dogs can fly.” Several forms of p → q p first q first “if p, then q” “q if p” “p implies q” “q whenever p” “if p, q” “q when p” “p only if q” “q is necessary for p” “p is sufficient for q” “q follows from p” “a necessary condition for p is q” “q unless ¬p” “a sufficient condition for q is p” • It is necessary to wash the boss’s car to get promoted. • Winds from the south imply a spring thaw. • A sufficient condition for the warranty to be good is that you bought the computer less than a year ago. • Willy gets caught whenever he cheats. • You can access the website only if you pay a subscription fee. • Getting elected follows from knowing the right people. • Carol gets seasick whenever she is on a boat. • Jane will go swimming unless the water is too cold Contrapositive, Converse and Inverse The contrapositive of p → q is the proposition ¬q →¬p. The converse of p → q is the proposition q → p. The inverse of p → q is the proposition ¬p →¬q. What are the contrapositive, the converse and the inverse of the conditional statements: 1. The home team wins whenever it is raining. 2. If Ali can swim across the lake, then Ali can swim to the island. 3. If today is Eid, then tomorrow is Monday. Biconditional Statements Let p and q be propositions. The biconditional statement p ↔ q is the proposition “p if and only if q.” It is also equivalent to (p → q) ∧ (q → p) The biconditional statement p ↔ q is true when p and q have the same truth values, and is false otherwise. Biconditional statements are also called bi-implications. Truth Table for Conditional Statements p q p↔q T T T T F F F T F F F T This computer program is correct if, and only if, it produces correct answers for all possible sets of input data. Exercise: Construct a truth table for the statement form p ∨ ¬ q → ¬ p. Logic and Bit Operations • Computers represent information using bits. • A bit is a symbol with two possible values, namely, 0 (zero) and 1 (one). • This meaning of the word bit comes from binary digit, because zeros and ones are the digits used in binary representations of numbers. • A bit can be used to represent a truth value, because there are two truth values, namely, true and false. • We will use a 1 bit to represent true and a 0 bit to represent false. • A variable is called a Boolean variable if its value is either true or false • Computer bit operations correspond to the logical connectives. • By replacing true by a one and false by a zero in the truth tables for the operators ∧, ∨, and ⊕, the tables for the corresponding bit operations can be obtained. • We will also use the notation OR, AND, and XOR for the operators ∨,∧, and ⊕, as is done in various programming languages. Truth Value Bit T 1 F 0 Table for the Bit Operators OR, AND, and XOR. y x∧y xvy x⊕y 1 1 1 1 0 1 0 0 1 1 0 1 0 1 1 0 0 0 0 0 x A bit string is a sequence of zero or one. The length of this string is the number of bits in the string. 101 1110 is a bit string of length 7. • We can extend bit operations to bit strings. We define the bitwise OR, bitwise AND, and bitwise XOR of two strings of the same length to be the strings that have as their bits the OR, AND, and XOR of the corresponding bits in the two strings, respectively. • We use the symbols ∨,∧, and ⊕ to represent the bitwise OR, bitwise AND, and bitwise XOR operations, respectively. Exercise: Find the bitwise OR, bitwise AND, and bitwise XOR of each of these pairs of bit strings. a) 101 1110, 010 0001 b) 1111 0000, 1010 1010 c) 00 0111 0001, 10 0100 1000 d) 11 1111 1111, 00 0000 0000 Exercise: Let p, q, and r be the propositions p : Grizzly bears have been seen in the area. q : Hiking is safe on the trail. r : Berries are ripe along the trail. Write these propositions using p, q, and r and logical connectives 1. Berries are ripe along the trail, but grizzly bears have not been seen in the area. 2. Grizzly bears have not been seen in the area and hiking on the trail is safe, but berries are ripe along the trail. 3. If berries are ripe along the trail, hiking is safe if and only if grizzly bears have not been seen in the area. 4. It is not safe to hike on the trail, but grizzly bears have not been seen in the area and the berries along the trail are ripe. 5. For hiking on the trail to be safe, it is necessary but not sufficient that berries not be ripe along the trail and for grizzly bears not to have been seen in the area. 6. Hiking is not safe on the trail whenever grizzly bears have been seen in the area and berries are ripe along the trail. Answer: 1) r∧¬p 2) ¬p∧q∧r 3) r →(q ↔¬p) 4) ¬q∧¬p ∧r 6) (p ∧ r) → ¬q 5) (q→(¬r ∧¬p))∧¬((¬r ∧¬p)→q) Exercise: For each of these sentences, state what the sentence means if the logical connective or is an inclusive or (that is, a disjunction) versus an exclusive or. Which of these meanings of or do you think is intended? 1. To take discrete mathematics, you must have taken calculus or a course in computer science. 2. When you buy a new car from Acme Motor Company, you get $2000 back in cash or a 2% car loan. 3. Dinner for two includes two items from column A or three items from column B. 4. School is closed if more than 2 feet of snow falls or if the wind chill is below −100. Answer: 1) Inclusive or 2) Exclusive or 3) Exclusive or 4) Inclusive or Exercise: Determine whether these biconditionals are true or false. a) 2 + 2 = 4 if and only if 1 + 1 = 2. b) 1 + 1 = 2 if and only if 2 + 3 = 4. c) 1 + 1 = 3 if and only if monkeys can fly. d) 0 > 1 if and only if 2 > 1. Applications of Propositional Logic Translating English Sentences: You can graduate only if you have completed the requirements of your major and you do not owe money to the university and you do not have an overdue library book. Express your answer in terms of g: “You can graduate,” m: “You owe money to the university,” r: “You have completed the requirements of your major,” and b: “You have an overdue library book.” System Specifications System and software engineers take requirements in natural language and produce precise and unambiguous specifications that can be used as the basis for system development. Express these system specifications using the propositions p “The message is scanned for viruses” and q “The message was sent from an unknown system” Together with logical connectives (including negations). 1. “The message is scanned for viruses whenever the message was sent from an unknown system.” 2. “The message was sent from an unknown system but it was not scanned for viruses.” 3. “It is necessary to scan the message for viruses whenever it was sent from an unknown system.” 4. “When a message is not sent from an unknown system it is not scanned for viruses.” Logic Puzzles Smullyan posed many puzzles about 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?” Logic Circuits • Find the output of the given digital circuit. Exercises from the Text Book • Exercise 1 page 12: Q# 1-39, Q. 42-44. (Section 1.1) • Exercise2 page 22: Q# 1-8, 18-23, 40-43. (Section 1.2)