<<

Introduction to CSE235 Introduction to Logic

Introduction

Usefulness of Logic

Propositional Slides by Christopher M. Bourke Equivalences Instructor: Berthe Y. Choueiry

Fall 2007 Science & Engineering 235 Introduction to Discrete Sections 1.1-1.2 of Rosen [email protected]

1 / 40 Introduction I

Introduction to Logic

CSE235

Introduction (or logic) is the study of the logical Connectives Truth Tables relationship between objects called propositions and forms the Usefulness of basis of all mathematical reasoning and all automated Logic reasoning. Propositional Equivalences Definition A is a that is either true or , but not both (we usually denote a proposition by letters; p, q, r, s, . . .).

2 / 40 Introduction II

Introduction to Logic Definition CSE235 The value of a proposition is called its ; denoted by Introduction Propositions T or 1 if it is true and F or 0 if it is false. Connectives Truth Tables Usefulness of Opinions, interrogative and imperative sentences are not Logic propositions. Propositional Equivalences :

p 0 1

3 / 40 Examples I

Introduction to Logic

CSE235 Example (Propositions) Introduction Propositions Today is Monday. Connectives Truth Tables The derivative of sin x is cos x. Usefulness of Logic Every even number has at least two factors. Propositional Equivalences Example (Not Propositions) C++ is the best language. When is the pretest? Do your homework.

4 / 40 Examples II

Introduction to Logic

CSE235

Introduction Propositions Connectives Truth Tables Example (Propositions?) Usefulness of 2 + 2 = 5 Logic

Propositional Every integer is divisible by 12. Equivalences Microsoft is an excellent company.

5 / 40 Logical Connectives

Introduction to Logic

CSE235 Connectives are used to create a compound proposition from Introduction Propositions two or more other propositions. Connectives Truth Tables Usefulness of (denoted ¬ or !) Logic

Propositional And (denoted ∧) or Logical Conjunction Equivalences Or (denoted ∨) or (XOR, denoted ⊕) Implication (denoted →) Biconditional; “” (denoted ↔)

6 / 40 Negation

Introduction to Logic A proposition can be negated. This is also a proposition. We CSE235 usually denote the negation of a proposition p by ¬p.

Introduction Propositions Example (Negated Propositions) Connectives Truth Tables Today is not Monday. Usefulness of Logic It is not the case that today is Monday. Propositional Equivalences It is not the case that the derivative of sin x is cos x.

Truth table:

p ¬p 0 1 1 0

7 / 40 Logical And

Introduction The is true only if both of the to Logic And propositions are true. It is also referred to as a conjunction. CSE235

Introduction Example (Logical Connective: And) Propositions Connectives It is raining and it is warm. Truth Tables √ Usefulness of (2 + 3 = 5) ∧ ( 2 < 2) Logic

Propositional Schr¨odinger’s cat is dead and Schr¨odinger’s cat is not Equivalences dead.

Truth table:

p q p ∧ q 0 0 0 0 1 0 1 0 0 8 / 40 1 1 1 Logical Or

Introduction to Logic The logical disjunction (or logical or) is true if one or both of

CSE235 the propositions are true.

Introduction Example (Logical Connective: Or) Propositions Connectives It is raining or it is the second day of lecture. Truth Tables √ Usefulness of Logic (2 + 2 = 5) ∨ ( 2 < 2) 1 Propositional You may have cake or ice cream. Equivalences

Truth table: p q p ∧ q p ∨ q 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 1

1 9 / 40 Can I have both? Exclusive Or

Introduction The exclusive or of two propositions is true when exactly one of to Logic its propositions is true and the other one is false. CSE235

Introduction Example (Logical Connective: Exclusive Or) Propositions Connectives The circuit is either is on or off. Truth Tables Usefulness of Let ab < 0, then either a < 0 or b < 0 but not both. Logic

Propositional You may have cake or ice cream, but not both. Equivalences Truth table:

p q p ⊕ q 0 0 0 0 1 1 1 0 1 1 1 0 10 / 40 Implications I

Introduction Definition to Logic

CSE235 Let p and q be propositions. The implication

Introduction Propositions p → q Connectives Truth Tables Usefulness of is the proposition that is false when p is true and q is false and Logic true otherwise. Propositional Equivalences Here, p is called the “hypothesis” (or “antecedent” or “premise”) and q is called the “conclusion” or “consequence”.

Truth table: p q p → q 0 0 1 0 1 1 1 0 0 1 1 1 11 / 40 Implications II

Introduction to Logic The implication p → q can be equivalently read as

CSE235 if p then q Introduction Propositions p implies q Connectives Truth Tables if p, q Usefulness of Logic p only if q Propositional Equivalences q if p q when p q whenever p p is a sufficient condition for q (p is sufficient for q) q is a necessary condition for p (q is necessary for p) q follows from p

12 / 40 Examples

Introduction to Logic

CSE235

Introduction Propositions Example Connectives Truth Tables If you buy your air ticket in advance, it is cheaper. Usefulness of Logic If x is a real number, then x2 ≥ 0. Propositional Equivalences If it rains, the grass gets wet. If the sprinklers operate, the grass gets wet. If 2 + 2 = 5 then all unicorns are pink.

13 / 40 true: the hypothesis is obviously false, thus no matter what the conclusion, the implication holds.

true: for the same reason as above

false: x can be any multiple of π; i.e. if we let x = 2π then clearly sin x = 0, but x 6= 0. The implication “if sin x = 0 then x = kπ for some integer k” is true.

Exercise

Introduction to Logic

CSE235 Which of the following implications is true? Introduction Propositions Connectives If −1 is a positive number, then 2 + 2 = 5. Truth Tables Usefulness of Logic

Propositional Equivalences If −1 is a positive number, then 2 + 2 = 4.

If sin x = 0 then x = 0.

14 / 40 true: for the same reason as above

false: x can be any multiple of π; i.e. if we let x = 2π then clearly sin x = 0, but x 6= 0. The implication “if sin x = 0 then x = kπ for some integer k” is true.

Exercise

Introduction to Logic

CSE235 Which of the following implications is true? Introduction Propositions Connectives If −1 is a positive number, then 2 + 2 = 5. Truth Tables true: the hypothesis is obviously false, thus no matter Usefulness of Logic what the conclusion, the implication holds. Propositional Equivalences If −1 is a positive number, then 2 + 2 = 4.

If sin x = 0 then x = 0.

14 / 40 false: x can be any multiple of π; i.e. if we let x = 2π then clearly sin x = 0, but x 6= 0. The implication “if sin x = 0 then x = kπ for some integer k” is true.

Exercise

Introduction to Logic

CSE235 Which of the following implications is true? Introduction Propositions Connectives If −1 is a positive number, then 2 + 2 = 5. Truth Tables true: the hypothesis is obviously false, thus no matter Usefulness of Logic what the conclusion, the implication holds. Propositional Equivalences If −1 is a positive number, then 2 + 2 = 4. true: for the same reason as above If sin x = 0 then x = 0.

14 / 40 Exercise

Introduction to Logic

CSE235 Which of the following implications is true? Introduction Propositions Connectives If −1 is a positive number, then 2 + 2 = 5. Truth Tables true: the hypothesis is obviously false, thus no matter Usefulness of Logic what the conclusion, the implication holds. Propositional Equivalences If −1 is a positive number, then 2 + 2 = 4. true: for the same reason as above If sin x = 0 then x = 0. false: x can be any multiple of π; i.e. if we let x = 2π then clearly sin x = 0, but x 6= 0. The implication “if sin x = 0 then x = kπ for some integer k” is true.

14 / 40 Biconditional

Introduction Definition to Logic The biconditional CSE235 p ↔ q Introduction Propositions Connectives is the proposition that is true when p and q have the same Truth Tables truth values. It is false otherwise. Usefulness of Logic Propositional Note that it is equivalent to (p → q) ∧ (q → p) Equivalences Truth table:

p q p → q q → p p ↔ q 0 0 1 1 1 0 1 1 0 0 1 0 0 1 0 1 1 1 1 1

15 / 40 Examples

Introduction to Logic CSE235 p ↔ q can be equivalently read as

Introduction Propositions p if and only if q Connectives Truth Tables p is necessary and sufficient for q Usefulness of Logic if p then q, and conversely Propositional Equivalences p iff q (Note typo in textbook, page 9, line 3.) Example x > 0 if and only if x2 is positive. The alarm goes off iff a burglar breaks in. You may have pudding if and only if you eat your meat.

16 / 40 true: both implications hold.

true: for the same reason above.

false: The holds. That is, “if x ≥ 0 then x2 ≥ 0”. However, the implication is false; consider x = −1. Then the hypothesis is true, (−1)2 = 12 ≥ 0 but the conclusion fails.

Exercise

Introduction to Logic

CSE235 Which of the following biconditionals is true? Introduction Propositions 2 2 Connectives x + y = 0 if and only if x = 0 and y = 0 Truth Tables Usefulness of √ Logic 2 + 2 = 4 if and only if 2 < 2 Propositional Equivalences x2 ≥ 0 if and only if x ≥ 0.

17 / 40 true: for the same reason above.

false: The converse holds. That is, “if x ≥ 0 then x2 ≥ 0”. However, the implication is false; consider x = −1. Then the hypothesis is true, (−1)2 = 12 ≥ 0 but the conclusion fails.

Exercise

Introduction to Logic

CSE235 Which of the following biconditionals is true? Introduction Propositions 2 2 Connectives x + y = 0 if and only if x = 0 and y = 0 Truth Tables true: both implications hold. Usefulness of √ Logic 2 + 2 = 4 if and only if 2 < 2 Propositional Equivalences x2 ≥ 0 if and only if x ≥ 0.

17 / 40 false: The converse holds. That is, “if x ≥ 0 then x2 ≥ 0”. However, the implication is false; consider x = −1. Then the hypothesis is true, (−1)2 = 12 ≥ 0 but the conclusion fails.

Exercise

Introduction to Logic

CSE235 Which of the following biconditionals is true? Introduction Propositions 2 2 Connectives x + y = 0 if and only if x = 0 and y = 0 Truth Tables true: both implications hold. Usefulness of √ Logic 2 + 2 = 4 if and only if 2 < 2 Propositional Equivalences true: for the same reason above. x2 ≥ 0 if and only if x ≥ 0.

17 / 40 Exercise

Introduction to Logic

CSE235 Which of the following biconditionals is true? Introduction Propositions 2 2 Connectives x + y = 0 if and only if x = 0 and y = 0 Truth Tables true: both implications hold. Usefulness of √ Logic 2 + 2 = 4 if and only if 2 < 2 Propositional Equivalences true: for the same reason above. x2 ≥ 0 if and only if x ≥ 0. false: The converse holds. That is, “if x ≥ 0 then x2 ≥ 0”. However, the implication is false; consider x = −1. Then the hypothesis is true, (−1)2 = 12 ≥ 0 but the conclusion fails.

17 / 40 Converse, Contrapositive, Inverse

Introduction to Logic

CSE235

Introduction Propositions Connectives Truth Tables Consider the proposition p → q: Usefulness of Logic Its converse is the proposistion q → p. Propositional Equivalences Its inverse is the proposistion ¬p → ¬q. Its contrapositive is the proposistion ¬q → ¬p.

18 / 40 Truth Tables I

Introduction to Logic

CSE235 Truth Tables are used to show the relationship between the truth values of individual propositions and the compound Introduction Propositions propositions based on them. Connectives Truth Tables Usefulness of Logic p q p ∧ q p ∨ q p ⊕ q p → q p ↔ q Propositional 0 0 0 0 0 1 1 Equivalences 0 1 0 1 1 1 0 1 0 0 1 1 0 0 1 1 1 1 0 1 1 Table: Truth Table for Logical Conjunction, Disjunction, Exclusive Or, and Implication

19 / 40 0 1 1 0 0 0 0 1 1 1 0 1

Constructing Truth Tables

Introduction to Logic

CSE235 Construct the Truth Table for the following compound Introduction Propositions proposition. Connectives Truth Tables ((p ∧ q) ∨ ¬q) Usefulness of Logic Propositional p q p ∧ q ¬q ((p ∧ q) ∨ ¬q) Equivalences 0 0 0 1 1 0 1 1

20 / 40 1 1 0 0 1 1 0 1

Constructing Truth Tables

Introduction to Logic

CSE235 Construct the Truth Table for the following compound Introduction Propositions proposition. Connectives Truth Tables ((p ∧ q) ∨ ¬q) Usefulness of Logic Propositional p q p ∧ q ¬q ((p ∧ q) ∨ ¬q) Equivalences 0 0 0 0 1 0 1 0 0 1 1 1

20 / 40 1 0 1 1

Constructing Truth Tables

Introduction to Logic

CSE235 Construct the Truth Table for the following compound Introduction Propositions proposition. Connectives Truth Tables ((p ∧ q) ∨ ¬q) Usefulness of Logic Propositional p q p ∧ q ¬q ((p ∧ q) ∨ ¬q) Equivalences 0 0 0 1 0 1 0 0 1 0 0 1 1 1 1 0

20 / 40 Constructing Truth Tables

Introduction to Logic

CSE235 Construct the Truth Table for the following compound Introduction Propositions proposition. Connectives Truth Tables ((p ∧ q) ∨ ¬q) Usefulness of Logic Propositional p q p ∧ q ¬q ((p ∧ q) ∨ ¬q) Equivalences 0 0 0 1 1 0 1 0 0 0 1 0 0 1 1 1 1 1 0 1

20 / 40 Precedence of Logical Operators

Introduction Just as in arithmetic, an ordering must be imposed on the use to Logic of logical operators in compound propositions. CSE235

Introduction Of course, parentheses can be used to make operators Propositions Connectives disambiguous: Truth Tables Usefulness of ¬p ∨ q ∧ ¬r ≡ (¬p) ∨ q ∧ (¬r) Logic

Propositional Equivalences But to avoid using unnecessary parentheses, we define the following precedences:

1 (¬) Negation 2 (∧) Conjunction 3 (∨) Disjunction 4 (→) Implication 5 (↔) Biconditional 21 / 40 Usefulness of Logic

Introduction to Logic CSE235 Logic is more precise than natural language:

Introduction

Usefulness of You may have cake or ice cream. Logic Can I have both? Bitwise Operations Logic in TCS If you buy your air ticket in advance, it is cheaper. Logic in Programming Are there or not cheap last-minute tickets? Propositional Equivalences For this reason, logic is used for hardware and software specification. Given a set of logic statements, one can decide whether or not they are satisfiable (i.e., consistent), although this is a costly process...

22 / 40 Bitwise Operations

Introduction represent information as bits (binary digits). to Logic CSE235 A bit string is a sequence of bits, the length of the string is the

Introduction number of bits in the string.

Usefulness of Logic Logical connectives can be applied to bit strings (of equal Bitwise Operations length). To do this, we simply apply the connective rules to Logic in TCS Logic in each bit of the string: Programming Propositional Equivalences Example 0110 1010 1101 0101 0010 1111 0111 1010 1111 bitwise Or 0100 0010 1101 bitwise And 0011 1000 0010 bitwise Xor

23 / 40 A Boolean variable is a variable that can have value 0 or 1. Logic in Theorerical Computer Science SAT

Introduction to Logic

CSE235

Introduction What is SAT? SAT is the problem of determining whether or

Usefulness of not a sentence in propositional logic (PL) is satisfiable. Logic Characterizing SAT as an NP-complete problem is at the Bitwise Operations Logic in TCS foundation of Theoretical Computer Science. Logic in Programming Defining SAT Propositional Equivalences Given: a PL sentence. Question: Determine whether it is satisfiable or not.

What is a PL sentence? What does satisfiable mean?

24 / 40 Logic in Theorerical Computer Science A sentence in PL

Introduction to Logic

CSE235

Introduction A sentence in PL is a conjunction of clauses Usefulness of Logic A clause is a disjunction of literals Bitwise Operations A literal is a term or its negation Logic in TCS Logic in Programming A term is a (Boolean) variable (or proposition) Propositional Equivalences Example: (a ∨ b ∨ ¬c ∨ ¬d) ∧ (¬b ∨ c) ∧ (¬a ∨ c ∨ d) A sentence in PL is a satisfiable iff we can assign truth value to the Boolean variables such that the sentence evaluates to true (i.e., holds).

25 / 40 if(x>0 AND x<=10) x++;

Logic in Programming Programming Example I

Introduction to Logic CSE235 Say you need to define a conditional statement as follows: Introduction “Increment x if all of the following conditions hold: x > 0, Usefulness of Logic x < 10 and x = 10.” Bitwise Operations Logic in TCS You may try: Logic in Programming if(0

26 / 40 Logic in Programming Programming Example I

Introduction to Logic CSE235 Say you need to define a conditional statement as follows: Introduction “Increment x if all of the following conditions hold: x > 0, Usefulness of Logic x < 10 and x = 10.” Bitwise Operations Logic in TCS You may try: Logic in Programming if(00 AND x<=10) x++;

26 / 40 Logic In Programming Programming Example II

Introduction Say we have the following loop: to Logic

CSE235 while Introduction ((i10) OR Usefulness of Logic (i= 10))))) Logic in TCS Logic in Programming Propositional Equivalences Is this good code? Keep in mind:

Readability. Extraneous code is inefficient and poor style. Complicated code is more prone to errors and difficult to debug.

27 / 40 Solution? Propositional Equivalences Introduction

Introduction to Logic

CSE235 To manipulate a set of statements (here, logical propositions) Introduction for the sake mathematical argumentation, an important step is Usefulness of Logic to replace one statement with another equivalent statement Propositional (i.e., with the same truth value). Equivalences Using TT Using L.E. Below, we discuss:

Terminology Establising logical equivalences using truth tables Establising logical equivalences using known laws (of logical equivalences)

28 / 40 Terminology Tautologies, , Contingencies

Introduction to Logic Definition CSE235 A compound proposition that is always true, no matter Introduction what the truth values of the propositions that occur in it is Usefulness of Logic called a . Propositional Equivalences A compound proposition that is always false is called a Using TT Using L.E. . Finally, a proposition that is neither a tautology nor a contradiction is called a contingency.

Example A simple tautology is p ∨ ¬p A simple contradiction is p ∧ ¬p

29 / 40 Logical Equivalences Definition

Introduction to Logic

CSE235 Definition Introduction

Usefulness of Propositions p and q are logically equivalent if p ↔ q is a Logic tautology. Propositional Equivalences Using TT Using L.E. Informally, p and q are logically equivalent if whenever p is true, q is true, and vice versa. Notation p ≡ q (“p is equivalent to q”), p ⇐⇒ q, p ⇔ q, p ↔ q. Alort: ≡ is not a logical connective.

30 / 40 1 1 0 0

The two columns in the truth table are identical, thus we conclude that p → q ≡ ¬p ∨ q

Example

Introduction to Logic Are and p → q and ¬p ∨ q logically equivalent? CSE235 To find out, we construct the truth tables for each: Introduction

Usefulness of Logic p q p → q ¬p ¬p ∨ q Propositional Equivalences 0 0 Using TT Using L.E. 0 1 1 0 1 1

31 / 40 1 1 0 0

The two columns in the truth table are identical, thus we conclude that p → q ≡ ¬p ∨ q

Example

Introduction to Logic Are and p → q and ¬p ∨ q logically equivalent? CSE235 To find out, we construct the truth tables for each: Introduction

Usefulness of Logic p q p → q ¬p ¬p ∨ q Propositional Equivalences 0 0 1 Using TT Using L.E. 0 1 1 1 0 0 1 1 1

31 / 40 The two columns in the truth table are identical, thus we conclude that p → q ≡ ¬p ∨ q

Example

Introduction to Logic Are and p → q and ¬p ∨ q logically equivalent? CSE235 To find out, we construct the truth tables for each: Introduction

Usefulness of Logic p q p → q ¬p ¬p ∨ q Propositional Equivalences 0 0 1 1 Using TT Using L.E. 0 1 1 1 1 0 0 0 1 1 1 0

31 / 40 The two columns in the truth table are identical, thus we conclude that p → q ≡ ¬p ∨ q

Example

Introduction to Logic Are and p → q and ¬p ∨ q logically equivalent? CSE235 To find out, we construct the truth tables for each: Introduction

Usefulness of Logic p q p → q ¬p ¬p ∨ q Propositional Equivalences 0 0 1 1 1 Using TT Using L.E. 0 1 1 1 1 1 0 0 0 0 1 1 1 0 1

31 / 40 Example

Introduction to Logic Are and p → q and ¬p ∨ q logically equivalent? CSE235 To find out, we construct the truth tables for each: Introduction

Usefulness of Logic p q p → q ¬p ¬p ∨ q Propositional Equivalences 0 0 1 1 1 Using TT Using L.E. 0 1 1 1 1 1 0 0 0 0 1 1 1 0 1

The two columns in the truth table are identical, thus we conclude that p → q ≡ ¬p ∨ q

31 / 40 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 0 0 1 1 1

Another Example

Introduction to Logic (Exercise 25 from Rosen): Show that CSE235

Introduction (p → r) ∨ (q → r) ≡ (p ∧ q) → r

Usefulness of Logic

Propositional p q r p → r (q → r) (p → r) ∨ (q → r) Equivalences Using TT 0 0 0 Using L.E. 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1

32 / 40 1 1 1 1 0 1 1 1 1 1 1 1 0 0 1 1

Another Example

Introduction to Logic (Exercise 25 from Rosen): Show that CSE235

Introduction (p → r) ∨ (q → r) ≡ (p ∧ q) → r

Usefulness of Logic

Propositional p q r p → r (q → r) (p → r) ∨ (q → r) Equivalences Using TT 0 0 0 1 Using L.E. 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 1

32 / 40 1 1 1 1 1 1 0 1

Another Example

Introduction to Logic (Exercise 25 from Rosen): Show that CSE235

Introduction (p → r) ∨ (q → r) ≡ (p ∧ q) → r

Usefulness of Logic

Propositional p q r p → r (q → r) (p → r) ∨ (q → r) Equivalences Using TT 0 0 0 1 1 Using L.E. 0 0 1 1 1 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1 1 0 1 1 1 1 1 0 0 0 1 1 1 1 1

32 / 40 Another Example

Introduction to Logic (Exercise 25 from Rosen): Show that CSE235

Introduction (p → r) ∨ (q → r) ≡ (p ∧ q) → r

Usefulness of Logic

Propositional p q r p → r (q → r) (p → r) ∨ (q → r) Equivalences Using TT 0 0 0 1 1 1 Using L.E. 0 0 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 0 0 0 1 1 1 0 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1

32 / 40 0 1 0 1 0 1 0 1 0 1 0 1 1 0 1 1

The truth values are identical, so we conclude that the logical equivalence holds.

Another Example Continued

Introduction to Logic Now let’s do it for (p ∧ q) → r:

CSE235

Introduction p q r p ∧ q (p ∧ q) → r Usefulness of Logic 0 0 0

Propositional 0 0 1 Equivalences Using TT 0 1 0 Using L.E. 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1

33 / 40 1 1 1 1 1 1 0 1

The truth values are identical, so we conclude that the logical equivalence holds.

Another Example Continued

Introduction to Logic Now let’s do it for (p ∧ q) → r:

CSE235

Introduction p q r p ∧ q (p ∧ q) → r Usefulness of Logic 0 0 0 0

Propositional 0 0 1 0 Equivalences Using TT 0 1 0 0 Using L.E. 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 1 1 1 1 1

33 / 40 The truth values are identical, so we conclude that the logical equivalence holds.

Another Example Continued

Introduction to Logic Now let’s do it for (p ∧ q) → r:

CSE235

Introduction p q r p ∧ q (p ∧ q) → r Usefulness of Logic 0 0 0 0 1

Propositional 0 0 1 0 1 Equivalences Using TT 0 1 0 0 1 Using L.E. 0 1 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 0 1 0 1 1 1 1 1

33 / 40 Another Example Continued

Introduction to Logic Now let’s do it for (p ∧ q) → r:

CSE235

Introduction p q r p ∧ q (p ∧ q) → r Usefulness of Logic 0 0 0 0 1

Propositional 0 0 1 0 1 Equivalences Using TT 0 1 0 0 1 Using L.E. 0 1 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 0 1 0 1 1 1 1 1

The truth values are identical, so we conclude that the logical equivalence holds. 33 / 40 Logical Equivalences Cheat Sheet

Introduction to Logic

CSE235

Introduction

Usefulness of Logic Tables of logical equivalences can be found in Rosen (page 24).

Propositional Equivalences These and other can be found in a handout on the course web Using TT Using L.E. page http://www.cse.unl.edu/~cse235/files/ LogicalEquivalences.pdf Let’s take a quick look at this Cheat Sheet

34 / 40 ⇐⇒ (¬p ∨ ¬q) ∨ q De Morgan’s Law (1st) ⇐⇒ ¬p ∨ (¬q ∨ q) Associative Law ⇐⇒ ¬p ∨ 1 Negation Law ⇐⇒ 1 Domination Law

Using Logical Equivalences Example 1

Introduction to Logic CSE235 Logical equivalences can be used to construct additional logical Introduction equivalences. Usefulness of Logic Example: Show that (p ∧ q) → q is a tautology Propositional Equivalences Using TT Using L.E. ((p ∧ q) → q) ⇐⇒ ¬(p ∧ q) ∨ q Implication Law

35 / 40 ⇐⇒ ¬p ∨ (¬q ∨ q) Associative Law ⇐⇒ ¬p ∨ 1 Negation Law ⇐⇒ 1 Domination Law

Using Logical Equivalences Example 1

Introduction to Logic CSE235 Logical equivalences can be used to construct additional logical Introduction equivalences. Usefulness of Logic Example: Show that (p ∧ q) → q is a tautology Propositional Equivalences Using TT Using L.E. ((p ∧ q) → q) ⇐⇒ ¬(p ∧ q) ∨ q Implication Law ⇐⇒ (¬p ∨ ¬q) ∨ q De Morgan’s Law (1st)

35 / 40 ⇐⇒ ¬p ∨ 1 Negation Law ⇐⇒ 1 Domination Law

Using Logical Equivalences Example 1

Introduction to Logic CSE235 Logical equivalences can be used to construct additional logical Introduction equivalences. Usefulness of Logic Example: Show that (p ∧ q) → q is a tautology Propositional Equivalences Using TT Using L.E. ((p ∧ q) → q) ⇐⇒ ¬(p ∧ q) ∨ q Implication Law ⇐⇒ (¬p ∨ ¬q) ∨ q De Morgan’s Law (1st) ⇐⇒ ¬p ∨ (¬q ∨ q) Associative Law

35 / 40 ⇐⇒ 1 Domination Law

Using Logical Equivalences Example 1

Introduction to Logic CSE235 Logical equivalences can be used to construct additional logical Introduction equivalences. Usefulness of Logic Example: Show that (p ∧ q) → q is a tautology Propositional Equivalences Using TT Using L.E. ((p ∧ q) → q) ⇐⇒ ¬(p ∧ q) ∨ q Implication Law ⇐⇒ (¬p ∨ ¬q) ∨ q De Morgan’s Law (1st) ⇐⇒ ¬p ∨ (¬q ∨ q) Associative Law ⇐⇒ ¬p ∨ 1 Negation Law

35 / 40 Using Logical Equivalences Example 1

Introduction to Logic CSE235 Logical equivalences can be used to construct additional logical Introduction equivalences. Usefulness of Logic Example: Show that (p ∧ q) → q is a tautology Propositional Equivalences Using TT Using L.E. ((p ∧ q) → q) ⇐⇒ ¬(p ∧ q) ∨ q Implication Law ⇐⇒ (¬p ∨ ¬q) ∨ q De Morgan’s Law (1st) ⇐⇒ ¬p ∨ (¬q ∨ q) Associative Law ⇐⇒ ¬p ∨ 1 Negation Law ⇐⇒ 1 Domination Law

35 / 40 ⇐⇒ (p → ¬q) ∧ (¬q → p) Equivalence Law ⇐⇒ (¬p ∨ ¬q) ∧ (q ∨ p) Implication Law ⇐⇒ ¬ (¬ ((¬p ∨ ¬q) ∧ (q ∨ p))) Double Negation ⇐⇒ ¬ (¬(¬p ∨ ¬q) ∨ ¬(q ∨ p)) De Morgan’s Law ⇐⇒ ¬ ((p ∧ q) ∨ (¬q ∧ ¬p)) De Morgan’s Law ⇐⇒ ¬ ((p ∧ q) ∨ (¬p ∧ ¬q)) Commutative Law ⇐⇒ ¬(p ↔ q) Equivalence Law (See Table 8, p25)

Using Logical Equivalences Example 2

Introduction Example (Exercise 17)1: Show that to Logic CSE235 ¬(p ↔ q) ⇐⇒ (p ↔ ¬q)

Introduction

Usefulness of Sometimes it helps to start out with the second proposition. Logic (p ↔ ¬q) Propositional Equivalences Using TT Using L.E.

1See Table 8 (p25), but you are not allowed to use the table for the 36 / 40 proof. ⇐⇒ (¬p ∨ ¬q) ∧ (q ∨ p) Implication Law ⇐⇒ ¬ (¬ ((¬p ∨ ¬q) ∧ (q ∨ p))) Double Negation ⇐⇒ ¬ (¬(¬p ∨ ¬q) ∨ ¬(q ∨ p)) De Morgan’s Law ⇐⇒ ¬ ((p ∧ q) ∨ (¬q ∧ ¬p)) De Morgan’s Law ⇐⇒ ¬ ((p ∧ q) ∨ (¬p ∧ ¬q)) Commutative Law ⇐⇒ ¬(p ↔ q) Equivalence Law (See Table 8, p25)

Using Logical Equivalences Example 2

Introduction Example (Exercise 17)1: Show that to Logic CSE235 ¬(p ↔ q) ⇐⇒ (p ↔ ¬q)

Introduction

Usefulness of Sometimes it helps to start out with the second proposition. Logic (p ↔ ¬q) Propositional Equivalences Using TT ⇐⇒ (p → ¬q) ∧ (¬q → p) Equivalence Law Using L.E.

1See Table 8 (p25), but you are not allowed to use the table for the 36 / 40 proof. ⇐⇒ ¬ (¬ ((¬p ∨ ¬q) ∧ (q ∨ p))) Double Negation ⇐⇒ ¬ (¬(¬p ∨ ¬q) ∨ ¬(q ∨ p)) De Morgan’s Law ⇐⇒ ¬ ((p ∧ q) ∨ (¬q ∧ ¬p)) De Morgan’s Law ⇐⇒ ¬ ((p ∧ q) ∨ (¬p ∧ ¬q)) Commutative Law ⇐⇒ ¬(p ↔ q) Equivalence Law (See Table 8, p25)

Using Logical Equivalences Example 2

Introduction Example (Exercise 17)1: Show that to Logic CSE235 ¬(p ↔ q) ⇐⇒ (p ↔ ¬q)

Introduction

Usefulness of Sometimes it helps to start out with the second proposition. Logic (p ↔ ¬q) Propositional Equivalences Using TT ⇐⇒ (p → ¬q) ∧ (¬q → p) Equivalence Law Using L.E. ⇐⇒ (¬p ∨ ¬q) ∧ (q ∨ p) Implication Law

1See Table 8 (p25), but you are not allowed to use the table for the 36 / 40 proof. ⇐⇒ ¬ (¬(¬p ∨ ¬q) ∨ ¬(q ∨ p)) De Morgan’s Law ⇐⇒ ¬ ((p ∧ q) ∨ (¬q ∧ ¬p)) De Morgan’s Law ⇐⇒ ¬ ((p ∧ q) ∨ (¬p ∧ ¬q)) Commutative Law ⇐⇒ ¬(p ↔ q) Equivalence Law (See Table 8, p25)

Using Logical Equivalences Example 2

Introduction Example (Exercise 17)1: Show that to Logic CSE235 ¬(p ↔ q) ⇐⇒ (p ↔ ¬q)

Introduction

Usefulness of Sometimes it helps to start out with the second proposition. Logic (p ↔ ¬q) Propositional Equivalences Using TT ⇐⇒ (p → ¬q) ∧ (¬q → p) Equivalence Law Using L.E. ⇐⇒ (¬p ∨ ¬q) ∧ (q ∨ p) Implication Law ⇐⇒ ¬ (¬ ((¬p ∨ ¬q) ∧ (q ∨ p))) Double Negation

1See Table 8 (p25), but you are not allowed to use the table for the 36 / 40 proof. ⇐⇒ ¬ ((p ∧ q) ∨ (¬q ∧ ¬p)) De Morgan’s Law ⇐⇒ ¬ ((p ∧ q) ∨ (¬p ∧ ¬q)) Commutative Law ⇐⇒ ¬(p ↔ q) Equivalence Law (See Table 8, p25)

Using Logical Equivalences Example 2

Introduction Example (Exercise 17)1: Show that to Logic CSE235 ¬(p ↔ q) ⇐⇒ (p ↔ ¬q)

Introduction

Usefulness of Sometimes it helps to start out with the second proposition. Logic (p ↔ ¬q) Propositional Equivalences Using TT ⇐⇒ (p → ¬q) ∧ (¬q → p) Equivalence Law Using L.E. ⇐⇒ (¬p ∨ ¬q) ∧ (q ∨ p) Implication Law ⇐⇒ ¬ (¬ ((¬p ∨ ¬q) ∧ (q ∨ p))) Double Negation ⇐⇒ ¬ (¬(¬p ∨ ¬q) ∨ ¬(q ∨ p)) De Morgan’s Law

1See Table 8 (p25), but you are not allowed to use the table for the 36 / 40 proof. ⇐⇒ ¬ ((p ∧ q) ∨ (¬p ∧ ¬q)) Commutative Law ⇐⇒ ¬(p ↔ q) Equivalence Law (See Table 8, p25)

Using Logical Equivalences Example 2

Introduction Example (Exercise 17)1: Show that to Logic CSE235 ¬(p ↔ q) ⇐⇒ (p ↔ ¬q)

Introduction

Usefulness of Sometimes it helps to start out with the second proposition. Logic (p ↔ ¬q) Propositional Equivalences Using TT ⇐⇒ (p → ¬q) ∧ (¬q → p) Equivalence Law Using L.E. ⇐⇒ (¬p ∨ ¬q) ∧ (q ∨ p) Implication Law ⇐⇒ ¬ (¬ ((¬p ∨ ¬q) ∧ (q ∨ p))) Double Negation ⇐⇒ ¬ (¬(¬p ∨ ¬q) ∨ ¬(q ∨ p)) De Morgan’s Law ⇐⇒ ¬ ((p ∧ q) ∨ (¬q ∧ ¬p)) De Morgan’s Law

1See Table 8 (p25), but you are not allowed to use the table for the 36 / 40 proof. ⇐⇒ ¬(p ↔ q) Equivalence Law (See Table 8, p25)

Using Logical Equivalences Example 2

Introduction Example (Exercise 17)1: Show that to Logic CSE235 ¬(p ↔ q) ⇐⇒ (p ↔ ¬q)

Introduction

Usefulness of Sometimes it helps to start out with the second proposition. Logic (p ↔ ¬q) Propositional Equivalences Using TT ⇐⇒ (p → ¬q) ∧ (¬q → p) Equivalence Law Using L.E. ⇐⇒ (¬p ∨ ¬q) ∧ (q ∨ p) Implication Law ⇐⇒ ¬ (¬ ((¬p ∨ ¬q) ∧ (q ∨ p))) Double Negation ⇐⇒ ¬ (¬(¬p ∨ ¬q) ∨ ¬(q ∨ p)) De Morgan’s Law ⇐⇒ ¬ ((p ∧ q) ∨ (¬q ∧ ¬p)) De Morgan’s Law ⇐⇒ ¬ ((p ∧ q) ∨ (¬p ∧ ¬q)) Commutative Law

1See Table 8 (p25), but you are not allowed to use the table for the 36 / 40 proof. Using Logical Equivalences Example 2

Introduction Example (Exercise 17)1: Show that to Logic CSE235 ¬(p ↔ q) ⇐⇒ (p ↔ ¬q)

Introduction

Usefulness of Sometimes it helps to start out with the second proposition. Logic (p ↔ ¬q) Propositional Equivalences Using TT ⇐⇒ (p → ¬q) ∧ (¬q → p) Equivalence Law Using L.E. ⇐⇒ (¬p ∨ ¬q) ∧ (q ∨ p) Implication Law ⇐⇒ ¬ (¬ ((¬p ∨ ¬q) ∧ (q ∨ p))) Double Negation ⇐⇒ ¬ (¬(¬p ∨ ¬q) ∨ ¬(q ∨ p)) De Morgan’s Law ⇐⇒ ¬ ((p ∧ q) ∨ (¬q ∧ ¬p)) De Morgan’s Law ⇐⇒ ¬ ((p ∧ q) ∨ (¬p ∧ ¬q)) Commutative Law ⇐⇒ ¬(p ↔ q) Equivalence Law (See Table 8, p25)

1See Table 8 (p25), but you are not allowed to use the table for the 36 / 40 proof. ⇐⇒ (¬(¬q ∨ p)) ∨ (p ∧ q) Implication Law ⇐⇒ (q ∧ ¬p) ∨ (p ∧ q) De Morgan’s & Double Negation ⇐⇒ (q ∧ ¬p) ∨ (q ∧ p) Commutative Law ⇐⇒ q ∧ (¬p ∨ p) Distributive Law ⇐⇒ q ∧ 1 Identity Law ⇐⇒ q Identity Law

Using Logical Equivalences Example 3

Introduction to Logic

CSE235 Show that ¬(q → p) ∨ (p ∧ q) ⇐⇒ q Introduction

Usefulness of Logic ¬(q → p) ∨ (p ∧ q) Propositional Equivalences Using TT Using L.E.

37 / 40 ⇐⇒ (q ∧ ¬p) ∨ (p ∧ q) De Morgan’s & Double Negation ⇐⇒ (q ∧ ¬p) ∨ (q ∧ p) Commutative Law ⇐⇒ q ∧ (¬p ∨ p) Distributive Law ⇐⇒ q ∧ 1 Identity Law ⇐⇒ q Identity Law

Using Logical Equivalences Example 3

Introduction to Logic

CSE235 Show that ¬(q → p) ∨ (p ∧ q) ⇐⇒ q Introduction

Usefulness of Logic ¬(q → p) ∨ (p ∧ q) Propositional Equivalences Using TT ⇐⇒ (¬(¬q ∨ p)) ∨ (p ∧ q) Implication Law Using L.E.

37 / 40 ⇐⇒ (q ∧ ¬p) ∨ (q ∧ p) Commutative Law ⇐⇒ q ∧ (¬p ∨ p) Distributive Law ⇐⇒ q ∧ 1 Identity Law ⇐⇒ q Identity Law

Using Logical Equivalences Example 3

Introduction to Logic

CSE235 Show that ¬(q → p) ∨ (p ∧ q) ⇐⇒ q Introduction

Usefulness of Logic ¬(q → p) ∨ (p ∧ q) Propositional Equivalences Using TT ⇐⇒ (¬(¬q ∨ p)) ∨ (p ∧ q) Implication Law Using L.E. ⇐⇒ (q ∧ ¬p) ∨ (p ∧ q) De Morgan’s & Double Negation

37 / 40 ⇐⇒ q ∧ (¬p ∨ p) Distributive Law ⇐⇒ q ∧ 1 Identity Law ⇐⇒ q Identity Law

Using Logical Equivalences Example 3

Introduction to Logic

CSE235 Show that ¬(q → p) ∨ (p ∧ q) ⇐⇒ q Introduction

Usefulness of Logic ¬(q → p) ∨ (p ∧ q) Propositional Equivalences Using TT ⇐⇒ (¬(¬q ∨ p)) ∨ (p ∧ q) Implication Law Using L.E. ⇐⇒ (q ∧ ¬p) ∨ (p ∧ q) De Morgan’s & Double Negation ⇐⇒ (q ∧ ¬p) ∨ (q ∧ p) Commutative Law

37 / 40 ⇐⇒ q ∧ 1 Identity Law ⇐⇒ q Identity Law

Using Logical Equivalences Example 3

Introduction to Logic

CSE235 Show that ¬(q → p) ∨ (p ∧ q) ⇐⇒ q Introduction

Usefulness of Logic ¬(q → p) ∨ (p ∧ q) Propositional Equivalences Using TT ⇐⇒ (¬(¬q ∨ p)) ∨ (p ∧ q) Implication Law Using L.E. ⇐⇒ (q ∧ ¬p) ∨ (p ∧ q) De Morgan’s & Double Negation ⇐⇒ (q ∧ ¬p) ∨ (q ∧ p) Commutative Law ⇐⇒ q ∧ (¬p ∨ p) Distributive Law

37 / 40 ⇐⇒ q Identity Law

Using Logical Equivalences Example 3

Introduction to Logic

CSE235 Show that ¬(q → p) ∨ (p ∧ q) ⇐⇒ q Introduction

Usefulness of Logic ¬(q → p) ∨ (p ∧ q) Propositional Equivalences Using TT ⇐⇒ (¬(¬q ∨ p)) ∨ (p ∧ q) Implication Law Using L.E. ⇐⇒ (q ∧ ¬p) ∨ (p ∧ q) De Morgan’s & Double Negation ⇐⇒ (q ∧ ¬p) ∨ (q ∧ p) Commutative Law ⇐⇒ q ∧ (¬p ∨ p) Distributive Law ⇐⇒ q ∧ 1 Identity Law

37 / 40 Using Logical Equivalences Example 3

Introduction to Logic

CSE235 Show that ¬(q → p) ∨ (p ∧ q) ⇐⇒ q Introduction

Usefulness of Logic ¬(q → p) ∨ (p ∧ q) Propositional Equivalences Using TT ⇐⇒ (¬(¬q ∨ p)) ∨ (p ∧ q) Implication Law Using L.E. ⇐⇒ (q ∧ ¬p) ∨ (p ∧ q) De Morgan’s & Double Negation ⇐⇒ (q ∧ ¬p) ∨ (q ∧ p) Commutative Law ⇐⇒ q ∧ (¬p ∨ p) Distributive Law ⇐⇒ q ∧ 1 Identity Law ⇐⇒ q Identity Law

37 / 40 Logic In Programming Programming Example II Revisited

Introduction to Logic

CSE235

Introduction Recall the loop: Usefulness of Logic

Propositional Equivalences while((i10) OR Using TT (i= 10)))))

Now, using logical equivalences, simplify it.

38 / 40 Logic In Programming Programming Example II Revisited

Introduction to Logic Answer: Use De Morgan’s Law and Distributivity. CSE235

Introduction while((i10 OR A[i]<0) OR

Propositional (A[i]==0 OR A[i]>=10))) Equivalences Using TT Using L.E. Notice the ranges of all four conditions on A[i]; they can be merged and we can further simplify it to:

while((i=10 OR A[i]<=0))

39 / 40 Programming Pitfall Note

Introduction to Logic

CSE235

Introduction In C, C++ and Java, applying the commutative law is not such a Usefulness of Logic good idea. These languages (compiler dependent) sometimes Propositional use “short-circuiting” for efficiency (at the machine level). For Equivalences Using TT example, consider accessing an integer array A of size n. Using L.E. if(i

40 / 40