Discrete Mathematics Ch1.1 Propositional Logic Dr. Talal Bonny 1 Definition of a Proposition A proposition (p, q, r, …) is simply a declarative statement with a definite meaning, having a truth value that’s either true (T) or false (F) (never both, neither, or somewhere in between). 2 Examples on Propositions “It is raining.” (Given a situation.) “UAE exports oil” “1 + 2 = 3” The following are NOT propositions: “Who’s there?” (interrogative, question) “Just do it!” (command) “1 + 2” (expression with a non-true/false value) 3 Propositional variables We use propositional variables to refer to propositions o Usually are lower case letters starting with p (i.e. p, q, r, s, etc.) o A propositional variable can have one of two values: true (T) or false (F) A proposition can be… o A single variable: p o An operation of multiple variables: p∧(q∨¬r) 4 Propositional Logic Propositional Logic is the logic of compound statements built from simpler statements using Boolean connectives. Applications: Design of digital electronic circuits. Expressing conditions in programs. Queries to databases & search engines. 5 Operators / Connectives An operator or connective combines one or more operand expressions into a larger expression. It is useful to establish analogy with traditional math (numbers): o E.g., “+ - * /” in numeric expression Unary operators take one operand (e.g., -3); Binary operators take two operands (eg 3 × 4). o Propositional or Boolean operators operate on propositions or truth values instead of on numbers. 6 Logical Operators ∧ Logical And P ∧ Q, (P ∧ Q) ∧ R, … ∨ Logical Or P ∨ Q, P ∨ (Q ∨ R), … ¬ Logical Not ¬P, ((¬P) ∧ Q), … → Logical Implication P→Q, (P∧Q)→Q, … ↔ Logical Equivalence P↔Q, (P∧Q)↔(Q∧P) ⊗ Exclusive Or P ⊗ Q, (P ∧ Q) ⊗ R, … Logical operators provide ways to combine propositions for calculation 7 Introduction to Logical Operators In the following examples, o p : “Today is Friday” o q : “Today is the beginning of Ramadan” o r:x>0 o s : x < 10 8 Logical conjunction operators: And An “and” operation is true if both operands are true Symbol: ∧ o It’s like the ‘A’ in And p ∧ q = r ∧ s = Note that a conjunction p 1 ∧ p2 ∧ … ∧ pn of n propositions will have p q p∧q F F F T F F T F F T T T rows in its truth table. 9 Logical disjunction operators: Or An “or” operation is true if either operands are true Symbol: ∨ P ∨ q = So this operation is p q p∨q F F F T F T T F T T T T also called “inclusive or”, because it includes the possibility that both p and q are true. 10 Logical operators: Not A “not” operation is true if operand is false. It switches (negates) the truth value Symbol: ¬ or ~ p ¬p ¬p = F T F ¬r = T 11 A Simple Exercise Let p = “It rained last night”, q = “The sprinklers came on last night,” r = “The grass was wet this morning.” Translate each of the following into English: ¬p = r ∧ ¬p = “Either the grass wasn’t wet this morning, or it rained last night, or = the sprinklers came on last night.” 12 Natural Language is Unclear Note that in English “or” is by itself corresponds to one of the two cases or “both”. If the “both” is excluded, then exclusive or ⊕ is used “Pat is a singer or Pat is a writer.” “Pat is a man or Pat is a woman.” - p F F T T q p or q F F T T F T T undef. 13 Logical operators: Exclusive Or An exclusive or operation is true if one of the operands are true, but false if both are true Symbol: ⊕ p q p⊕q Often called XOR F F To write it using logical operators F T F T and based on ∨ table T F p⊕q ≡ (p ∨ q) ∧ ¬(p ∧ q) T T T F o p = “Today is Friday” o q = “Today is the beginning of Ramadan” p⊕q = 14 Examples Assume P = x > 0, Q = y > 0 If P ⊗ Q is True, in which quadrant should be (x, y)? If P ∧ Q is True, in which quadrant should be (x, y)? If P ∨ Q is True, in which quadrant should be (x, y)? If ¬ P is True, in which quadrant should be (x, y)? y Quadrant 2 Quadrant 1 x < 0, y > 0 x > 0, y > 0 x Quadrant 3 Quadrant 4 x < 0, y < 0 x > 0, y < 0 15 Inclusive Or versus Exclusive Or Do these sentences mean inclusive or exclusive or? o Experience with C++ or Java is required o Lunch includes soup or salad o To enter the country, you need a passport or a driver’s license 16 Conditional Statement Let p and q be propositions. The conditional statement p→q is false when p is true and q is false, and true otherwise A conditional means “if p then q” p→q p q Symbol: → T F F o p is called the hypothesis o q is called the conclusion o p→q is called implication F T T F T F T T T Note that if p is false, then the conditional statement is true regardless of whether q is true or false 17 Conditional Statement Example 1 p = “the student is studying engineering” q = “s/he is smart” p→q = o “If the student is studying engineering, then s/he is smart” TRUE o “If the student is not studying engineering, then s/he is smart” TRUE He is studying business for ex. o “If the student is not studying engineering, then s/he is not smart” TRUE p q p→q F F F T T F T T F T T T He is not studying at all o “If the student is studying engineering, then s/he is not smart” FALSE. Not correct because he can not continue studying 18 Conditional Statement Example 2 p = “you get 100% on the final” q = “you will get an A” p→q = o “If you get 100% on the final, then you will get an A” TRUE o “If you did not get 100% on the final, then you may get an A” TRUE (if you get 90% and above) o “If you did not get 100% on the final, then you may not get an A” TRUE p q p→q F F F T T F T T F T T T (if you get less than 90%) o “If you get 100% on the final, then you will not get an A” FALSE not allowed, you will feel cheated 19 Conditional Statement To write it using logical operator: p→q=¬p∨ q Ex.1: The student is not studying engineering or s/he is smart Ex.2: you did not get 100% on the final or you will get an A Alternate ways of stating a conditional statements: o o o o o o o p implies q If p, q p only if q p is sufficient for q q if p q whenever p q is necessary for p 20 Conditional Statement (Cont.) p is not sufficient for q = ¬ (p→q) p q ¬p ¬q Conditional Inverse p→q ¬p→¬q Converse Contrapositive q→p ¬q→¬p F F F T T F T T 21 Bi-conditional Statement P↔q: a bi-conditional means “p if and only if q” Symbol: ↔ Alternatively, it means “(if p then q) and (if q then p)” Let p = “the student is studying engineering” and q = “s/he is smart”, then p↔q means o “the student is studying engineering if and only if s/he is smart” o Alternatively, it means “If the student is smart, then s/he is studying engineering” and if the student is studying engineering then s/he is smart 22 Bi-conditional Statement To write it using logical operator: p→q ∧ q→p = (¬p∨ q) ∧ (¬q∨ p) Alternate ways of stating a conditional statements: o “p is necessary and sufficient for q” o “if p then q, and conversely” o “p iff q” 23 Boolean operators summary p q F F F T T F T T not not and or xor conditional Bi-conditional ¬p ¬q p∧q p∨q p⊕q p→q p↔q Learn what they mean, don’t just memorize the table! 24 Precedence of operators Just as in algebra, operators have precedence o 4+3*2 = o 4+(3*2) = 10 but not (4+3)*2 = 14 Precedence order (from highest to lowest): Example: p ∨ q ∧ ¬r → s ↔ t 25 Bit Operations The word bit comes from binary digit Boolean values can be represented as 1 (true) and 0 (false) o By replacing true by a one o and false by a zero in the truth table Truth tables for AND, OR, XOR Boolean variable in programming language or database systems can be stored in 1 bit 26 Bit Operations A bit string is a series of Boolean values. The length of this string is the number of bits o in the string 10110100 is eight Boolean values in one string We can then do operations on these Boolean strings o Each column is its own Boolean operation Find the bitwise OR, bitwise AND, and bitwise XOR of the bit strings 01011010 and 10110100 01011010 ∧10110100 01011010 ∨10110100 01011010 ⊕10110100 27 Examples 28 Apply the alternate ways of the conditional statement on the previous example: p = “you get 100% on the final” q = “you will get an A” Alternate ways of stating a conditional statements: o If p, q o p only if q o q if p 29 Example1 Question 7 from Rosen, p. 17 (Translating English Sentences ) o p = “It is below freezing” o q = “It is snowing” Write these propositions using p and q and logical connectives It is below freezing and it is snowing It is below freezing but not snowing It is not below freezing and it is not snowing It is either snowing or below freezing (or both) If it is below freezing, it is also snowing That it is below freezing is necessary and sufficient for it to be snowing 30 Example 2 Express the following as a logical Expression:“I have neither given nor received help on this exam” Let p = “I have given help on this exam” Let q = “I have received help on this exam” 31 Example 3 Express the following as a logical Expression: You can access the Internet from campus only if you are a computer engineer major or you are not a freshman. Let a represents "You can access the Internet from campus" Let c represents "You are a computer engineer major," and Let f represents "You are a freshman,“ 32 Example 4 Construct the truth table of the logical Expression: ((P ∨ Q)∧((¬P)→Q)) P Q False False False True True False True True (P ∨ Q) (¬P) ((¬P)→Q) ((P∨Q)∧((¬P)→Q)) 33 Example 5 Construct the truth table of the logical Expression: (((¬P)∧Q)∧((¬P)→Q)) P Q (¬P) ((¬P)∧Q) ((¬P)→Q) ( (((¬P)∧Q) ∧((¬P)→Q)) False False False False True True True False False True True False 34 Example 7: Bit Operations Evaluate the following expressions o (11011 ∨ 01010) ∧ (10001 ∨ 11011) o 11011 ∨ 01010 ∧ 10001 ∨ 11011 35