Introduction to Logic CSE235 Slides by Christopher M. Bourke - - PowerPoint PPT Presentation

introduction to logic
SMART_READER_LITE
LIVE PREVIEW

Introduction to Logic CSE235 Slides by Christopher M. Bourke - - PowerPoint PPT Presentation

Introduction to Logic Introduction to Logic CSE235 Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry Spring 2006 Computer Science & Engineering 235 Introduction to Discrete Mathematics Sections 1.1-1.2 of Rosen 1 / 1


slide-1
SLIDE 1

Introduction to Logic CSE235

Introduction to Logic

Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry Spring 2006 Computer Science & Engineering 235 Introduction to Discrete Mathematics

Sections 1.1-1.2 of Rosen cse235@cse.unl.edu

1 / 1

slide-2
SLIDE 2

Introduction to Logic CSE235

Introduction I

Propositional calculus (or logic) is the study of the logical relationship between objects called propositions and forms the basis of all mathematical reasoning.

Definition

A proposition is a statement that is either true or false, but not both (we usually denote a proposition by letters; p, q, r, s, . . .).

2 / 1

slide-3
SLIDE 3

Introduction to Logic CSE235

Introduction II

Definition

The value of a proposition is called its truth value; denoted by T or 1 if it is true and F or 0 if it is false. Opinions, interrogative and imperative sentences are not propositions. Truth table: p 1

3 / 1

slide-4
SLIDE 4

Introduction to Logic CSE235

Examples I

Example (Propositions)

Today is Monday. The derivative of sin x is cos x. Every even number has at least two factors.

Example (Not Propositions)

C++ is the best language. When is the pretest? Do your homework.

4 / 1

slide-5
SLIDE 5

Introduction to Logic CSE235

Logical Connectives

Connectives are used to create a compound proposition from two or more other propositions. Negation (denoted ¬ or !) And (denoted ∧) or Logical Conjunction Or (denoted ∨) or Logical Disjunction Exclusive Or (XOR, denoted ⊕) Implication (denoted →) Biconditional; “if and only if” (denoted ↔)

6 / 1

slide-6
SLIDE 6

Introduction to Logic CSE235

Negation

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

Example (Negated Propositions)

Today is not Monday. It is not the case that today is Monday. It is not the case that the derivative of sin x is cos x. Truth table: p ¬p 1 1

7 / 1

slide-7
SLIDE 7

Introduction to Logic CSE235

Logical And

The logical connective And is true only if both of the propositions are true. It is also referred to as a conjunction.

Example (Logical Connective: And)

It is raining and it is warm. (2 + 3 = 5) ∧ ( √ 2 < 2) Schr¨

  • dinger’s cat is dead and Schr¨
  • dinger’s cat is not

dead. Truth table: p q p ∧ q 1 1 1 1 1

8 / 1

slide-8
SLIDE 8

Introduction to Logic CSE235

Logical Or

The logical disjunction (or logical or) is true if one or both of the propositions are true.

Example (Logical Connective: Or)

It is raining or it is the second day of lecture. (2 + 2 = 5) ∨ ( √ 2 < 2) You may have cake or ice cream.1 Truth table: p q p ∧ q p ∨ q 1 1 1 1 1 1 1 1

1Can I have both? 9 / 1

slide-9
SLIDE 9

Introduction to Logic CSE235

Exclusive Or

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

Example (Logical Connective: Exclusive Or)

The circuit is either is on or off. Let ab < 0, then either a < 0 or b < 0 but not both. You may have cake or ice cream, but not both. Truth table: p q p ⊕ q 1 1 1 1 1 1

10 / 1

slide-10
SLIDE 10

Introduction to Logic CSE235

Implications I

Definition

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. Here, p is called the “hypothesis” (or “antecedent” or “premise”) and q is called the “conclusion” or “consequence”. Truth table: p q p → q 1 1 1 1 1 1 1

11 / 1

slide-11
SLIDE 11

Introduction to Logic CSE235

Implications II

The implication p → q can be equivalently read as if p then q p implies q if p, q p only if q 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 / 1

slide-12
SLIDE 12

Introduction to Logic CSE235

Examples

Example

If you buy your air ticket in advance, it is cheaper. If 2 + 2 = 5 then all unicorns are pink. If x is a real number, then x2 ≥ 0. If it rains, the grass gets wet. If the sprinklers operate, the grass gets wet.

13 / 1

slide-13
SLIDE 13

Introduction to Logic CSE235

Exercise

Which of the following implications is true? If −1 is a positive number, then 2 + 2 = 5. If −1 is a positive number, then 2 + 2 = 4. If sin x = 0 then x = 0.

14 / 1

slide-14
SLIDE 14

Introduction to Logic CSE235

Exercise

Which of the following implications is true? If −1 is a positive number, then 2 + 2 = 5. true: the hypothesis is obviously false, thus no matter what the conclusion, the implication holds. If −1 is a positive number, then 2 + 2 = 4. If sin x = 0 then x = 0.

15 / 1

slide-15
SLIDE 15

Introduction to Logic CSE235

Exercise

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

16 / 1

slide-16
SLIDE 16

Introduction to Logic CSE235

Exercise

Which of the following implications is true? If −1 is a positive number, then 2 + 2 = 5. true: the hypothesis is obviously false, thus no matter what the conclusion, the implication holds. 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 = 0. The implication “if sin x = 0 then x = kπ for some integer k” is true.

17 / 1

slide-17
SLIDE 17

Introduction to Logic CSE235

Biconditional

Definition

The biconditional p ↔ q is the proposition that is true when p and q have the same truth values. It is false otherwise. Note that it is equivalent to (p → q) ∧ (q → p) Truth table: p q p → q q → p p ↔ q 1 1 1 1 1 1 1 1 1 1 1 1

18 / 1

slide-18
SLIDE 18

Introduction to Logic CSE235

Examples

p ↔ q can be equivalently read as p if and only if q p is necessary and sufficient for q if p then q, and conversely 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.1

1How can you have any pudding if you don’t eat your meat? 19 / 1

slide-19
SLIDE 19

Introduction to Logic CSE235

Exercise

Which of the following biconditionals is true? x2 + y2 = 0 if and only if x = 0 and y = 0 2 + 2 = 4 if and only if √ 2 < 2 x2 ≥ 0 if and only if x ≥ 0.

20 / 1

slide-20
SLIDE 20

Introduction to Logic CSE235

Exercise

Which of the following biconditionals is true? x2 + y2 = 0 if and only if x = 0 and y = 0 true: both implications hold. 2 + 2 = 4 if and only if √ 2 < 2 x2 ≥ 0 if and only if x ≥ 0.

21 / 1

slide-21
SLIDE 21

Introduction to Logic CSE235

Exercise

Which of the following biconditionals is true? x2 + y2 = 0 if and only if x = 0 and y = 0 true: both implications hold. 2 + 2 = 4 if and only if √ 2 < 2 true: for the same reason above. x2 ≥ 0 if and only if x ≥ 0.

22 / 1

slide-22
SLIDE 22

Introduction to Logic CSE235

Exercise

Which of the following biconditionals is true? x2 + y2 = 0 if and only if x = 0 and y = 0 true: both implications hold. 2 + 2 = 4 if and only if √ 2 < 2 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, 12 ≥ 0 but the conclusion fails.

23 / 1

slide-23
SLIDE 23

Introduction to Logic CSE235

Converse, Contrapositive, Inverse

Consider the proposition p → q: Its converse is the proposistion q → p. Its inverse is the proposistion ¬p → ¬q. Its contrapositive is the proposistion ¬q → ¬p.

24 / 1

slide-24
SLIDE 24

Correct or Incorrect?

If x is divisible by 4, then x is even.

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-25
SLIDE 25

Correct or Incorrect?

If x is divisible by 4, then x is even. p → q, where p is ‘x is divisible by 4’ and q is ‘x is even’.

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-26
SLIDE 26

Correct or Incorrect?

If x is divisible by 4, then x is even. p → q, where p is ‘x is divisible by 4’ and q is ‘x is even’. q → p

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-27
SLIDE 27

Correct or Incorrect?

If x is divisible by 4, then x is even. p → q, where p is ‘x is divisible by 4’ and q is ‘x is even’. q → p : If x is even, then x is divisible by 4

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-28
SLIDE 28

Correct or Incorrect?

If x is divisible by 4, then x is even. p → q, where p is ‘x is divisible by 4’ and q is ‘x is even’. q → p : If x is even, then x is divisible by 4 Incorrect

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-29
SLIDE 29

Correct or Incorrect?

If x is divisible by 4, then x is even. p → q, where p is ‘x is divisible by 4’ and q is ‘x is even’. q → p : If x is even, then x is divisible by 4 Incorrect ¬p → ¬q

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-30
SLIDE 30

Correct or Incorrect?

If x is divisible by 4, then x is even. p → q, where p is ‘x is divisible by 4’ and q is ‘x is even’. q → p : If x is even, then x is divisible by 4 Incorrect ¬p → ¬q : If x is not divisible by 4, then x is not even

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-31
SLIDE 31

Correct or Incorrect?

If x is divisible by 4, then x is even. p → q, where p is ‘x is divisible by 4’ and q is ‘x is even’. q → p : If x is even, then x is divisible by 4 Incorrect ¬p → ¬q : If x is not divisible by 4, then x is not even Incorrect

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-32
SLIDE 32

Correct or Incorrect?

If x is divisible by 4, then x is even. p → q, where p is ‘x is divisible by 4’ and q is ‘x is even’. q → p : If x is even, then x is divisible by 4 Incorrect ¬p → ¬q : If x is not divisible by 4, then x is not even Incorrect ¬q → ¬p

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-33
SLIDE 33

Correct or Incorrect?

If x is divisible by 4, then x is even. p → q, where p is ‘x is divisible by 4’ and q is ‘x is even’. q → p : If x is even, then x is divisible by 4 Incorrect ¬p → ¬q : If x is not divisible by 4, then x is not even Incorrect ¬q → ¬p : If x is not even, then x is not divisible by 4.

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-34
SLIDE 34

Correct or Incorrect?

If x is divisible by 4, then x is even. p → q, where p is ‘x is divisible by 4’ and q is ‘x is even’. q → p : If x is even, then x is divisible by 4 Incorrect ¬p → ¬q : If x is not divisible by 4, then x is not even Incorrect ¬q → ¬p : If x is not even, then x is not divisible by 4. Correct

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-35
SLIDE 35

Introduction to Logic CSE235

Truth Tables I

Truth Tables are used to show the relationship between the truth values of individual propositions and the compound propositions based on them. p q p ∧ q p ∨ q p ⊕ q p → q p ↔ q 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Table: Truth Table for Logical Conjunction, Disjunction, Exclusive Or, and Implication

25 / 1

slide-36
SLIDE 36

Introduction to Logic CSE235

Constructing Truth Tables

Construct the Truth Table for the following compound proposition. ((p ∧ q) ∨ ¬q) p q p ∧ q ¬q ((p ∧ q) ∨ ¬q) 1 1 1 1

26 / 1

slide-37
SLIDE 37

Introduction to Logic CSE235

Constructing Truth Tables

Construct the Truth Table for the following compound proposition. ((p ∧ q) ∨ ¬q) p q p ∧ q ¬q ((p ∧ q) ∨ ¬q) 1 1 1 1 1

27 / 1

slide-38
SLIDE 38

Introduction to Logic CSE235

Constructing Truth Tables

Construct the Truth Table for the following compound proposition. ((p ∧ q) ∨ ¬q) p q p ∧ q ¬q ((p ∧ q) ∨ ¬q) 1 1 1 1 1 1 1

28 / 1

slide-39
SLIDE 39

Introduction to Logic CSE235

Constructing Truth Tables

Construct the Truth Table for the following compound proposition. ((p ∧ q) ∨ ¬q) p q p ∧ q ¬q ((p ∧ q) ∨ ¬q) 1 1 1 1 1 1 1 1 1 1

29 / 1

slide-40
SLIDE 40

Predicate Logic and Quantifiers CSE235

Propositional Functions

Definition

A statement of the form P(x1, x2, . . . , xn) is the value of the propositional function P. Here, (x1, x2, . . . , xn) is an n-tuple and P is a predicate. You can think of a propositional function as a function that Evaluates to true or false. Takes one or more arguments. Expresses a predicate involving the argument(s). Becomes a proposition when values are assigned to the arguments.

4 / 1

slide-41
SLIDE 41

Predicate Logic and Quantifiers CSE235

Propositional Functions

Example

Example

Let Q(x, y, z) denote the statement “x2 + y2 = z2”. What is the truth value of Q(3, 4, 5)? What is the truth value of Q(2, 2, 3)? How many values of (x, y, z) make the predicate true?

5 / 1

slide-42
SLIDE 42

Predicate Logic and Quantifiers CSE235

Propositional Functions

Example

Example

Let Q(x, y, z) denote the statement “x2 + y2 = z2”. What is the truth value of Q(3, 4, 5)? What is the truth value of Q(2, 2, 3)? How many values of (x, y, z) make the predicate true? Since 32 + 42 = 25 = 52, Q(3, 4, 5) is true. Since 22 + 22 = 8 = 32 = 9, Q(2, 2, 3) is false. There are infinitely many values for (x, y, z) that make this propositional function true—how many right triangles are there?

6 / 1

slide-43
SLIDE 43

Predicate Logic and Quantifiers CSE235

Quantifiers

Introduction

A predicate becomes a proposition when we assign it fixed

  • values. However, another way to make a predicate into a

proposition is to quantify it. That is, the predicate is true (or false) for all possible values in the universe of discourse or for some value(s) in the universe of discourse. Such quantification can be done with two quantifiers: the universal quantifier and the existential quantifier.

9 / 1

slide-44
SLIDE 44

Predicate Logic and Quantifiers CSE235

Universal Quantifier

Definition

Definition

The universal quantification of a predicate P(x) is the proposition “P(x) is true for all values of x in the universe of discourse” We use the notation ∀xP(x) which can be read “for all x” If the universe of discourse is finite, say {n1, n2, . . . , nk}, then the universal quantifier is simply the conjunction of all elements: ∀xP(x) ⇐ ⇒ P(n1) ∧ P(n2) ∧ · · · ∧ P(nk)

10 / 1

slide-45
SLIDE 45

Predicate Logic and Quantifiers CSE235

Universal Quantifier

Example I

Let P(x) be the predicate “x must take a discrete mathematics course” and let Q(x) be the predicate “x is a computer science student”. The universe of discourse for both P(x) and Q(x) is all UNL students. Express the statement “Every computer science student must take a discrete mathematics course”. Express the statement “Everybody must take a discrete mathematics course or be a computer science student”.

11 / 1

slide-46
SLIDE 46

Predicate Logic and Quantifiers CSE235

Universal Quantifier

Example I

Let P(x) be the predicate “x must take a discrete mathematics course” and let Q(x) be the predicate “x is a computer science student”. The universe of discourse for both P(x) and Q(x) is all UNL students. Express the statement “Every computer science student must take a discrete mathematics course”. ∀x(Q(x) → P(x)) Express the statement “Everybody must take a discrete mathematics course or be a computer science student”.

12 / 1

slide-47
SLIDE 47

Predicate Logic and Quantifiers CSE235

Universal Quantifier

Example I

Let P(x) be the predicate “x must take a discrete mathematics course” and let Q(x) be the predicate “x is a computer science student”. The universe of discourse for both P(x) and Q(x) is all UNL students. Express the statement “Every computer science student must take a discrete mathematics course”. ∀x(Q(x) → P(x)) Express the statement “Everybody must take a discrete mathematics course or be a computer science student”. ∀x(Q(x) ∨ P(x))

13 / 1

slide-48
SLIDE 48

Predicate Logic and Quantifiers CSE235

Universal Quantifier

Example I

Let P(x) be the predicate “x must take a discrete mathematics course” and let Q(x) be the predicate “x is a computer science student”. The universe of discourse for both P(x) and Q(x) is all UNL students. Express the statement “Every computer science student must take a discrete mathematics course”. ∀x(Q(x) → P(x)) Express the statement “Everybody must take a discrete mathematics course or be a computer science student”. ∀x(Q(x) ∨ P(x)) Are these statements true or false?

14 / 1

slide-49
SLIDE 49

Predicate Logic and Quantifiers CSE235

Existential Quantifier

Definition

Definition

The existential quantification of a predicate P(x) is the proposition “There exists an x in the universe of discourse such that P(x) is true.” We use the notation ∃xP(x) which can be read “there exists an x” Again, if the universe of discourse is finite, {n1, n2, . . . , nk}, then the existential quantifier is simply the disjunction of all elements: ∃xP(x) ⇐ ⇒ P(n1) ∨ P(n2) ∨ · · · ∨ P(nk)

19 / 1

slide-50
SLIDE 50

Predicate Logic and Quantifiers CSE235

Quantifiers

Truth Values

In general, when are quantified statements true/false? Statement True When False When ∀xP(x) P(x) is true for every x. There is an x for which P(x) is false. ∃xP(x) There is an x for which P(x) is true. P(x) is false for every x.

Table: Truth Values of Quantifiers

27 / 1

slide-51
SLIDE 51

Predicate Logic and Quantifiers CSE235

Mixing Quantifiers I

Existential and universal quantifiers can be used together to quantify a predicate statement; for example, ∀x∃yP(x, y) is perfectly valid. However, you must be careful—it must be read left to right. For example, ∀x∃yP(x, y) is not equivalent to ∃y∀xP(x, y). Thus, ordering is important.

28 / 1

slide-52
SLIDE 52

Predicate Logic and Quantifiers CSE235

Mixing Quantifiers II

For example: ∀x∃yLoves(x, y): everybody loves somebody ∃y∀xLoves(x, y): There is someone loved by everyone Those expressions do not mean the same thing! Note that ∃y∀xP(x, y) → ∀x∃yP(x, y), but the converse does not hold However, you can commute similar quantifiers; ∃x∃yP(x, y) is equivalent to ∃y∃xP(x, y) (which is why our shorthand was valid).

29 / 1

slide-53
SLIDE 53

Predicate Logic and Quantifiers CSE235

Mixing Quantifiers

Truth Values

Statement True When False When ∀x∀yP(x, y) P(x, y) is true for ev- ery pair x, y. There is at least one pair, x, y for which P(x, y) is false. ∀x∃yP(x, y) For every x, there is a y for which P(x, y) is true. There is an x for which P(x, y) is false for every y. ∃x∀yP(x, y) There is an x for which P(x, y) is true for every y. For every x, there is a y for which P(x, y) is false. ∃x∃yP(x, y) There is at least one pair x, y for which P(x, y) is true. P(x, y) is false for ev- ery pair x, y.

Table: Truth Values of 2-variate Quantifiers

30 / 1

slide-54
SLIDE 54

Predicate Logic and Quantifiers CSE235

Negation

Just as we can use negation with propositions, we can use them with quantified expressions.

Lemma

Let P(x) be a predicate. Then the following hold. ¬∀xP(x) ≡ ∃x¬P(x) ¬∃xP(x) ≡ ∀x¬P(x) This is essentially a quantified version of De Morgan’s Law (in fact if the universe of discourse is finite, it is exactly De Morgan’s law).

54 / 1

slide-55
SLIDE 55

Predicate Logic and Quantifiers CSE235

Negation

Truth Values

Statement True When False When ¬∃xP(x) ≡ ∀x¬P(x) For every x, P(x) is false. There is an x for which P(x) is true. ¬∀xP(x) ≡ ∃x¬P(x) There is an x for which P(x) is false. P(x) is true for every x.

Table: Truth Values of Negated Quantifiers

55 / 1

slide-56
SLIDE 56

Correct or Incorrect?

If I go for a walk, then it is not raining. It is not raining. Therefore, I go for a walk.

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-57
SLIDE 57

Correct or Incorrect?

If I go for a walk, then it is not raining. It is not raining. Therefore, I go for a walk. Incorrect

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-58
SLIDE 58

Correct or Incorrect?

If I go for a walk, then it is not raining. It is not raining. Therefore, I go for a walk. Incorrect If I go for a walk, then it is not raining. I go for a walk. Therefore, it is not raining.

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-59
SLIDE 59

Correct or Incorrect?

If I go for a walk, then it is not raining. It is not raining. Therefore, I go for a walk. Incorrect If I go for a walk, then it is not raining. I go for a walk. Therefore, it is not raining. Correct

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-60
SLIDE 60

Correct or Incorrect?

If I go for a walk, then it is not raining. It is not raining. Therefore, I go for a walk. Incorrect If I go for a walk, then it is not raining. I go for a walk. Therefore, it is not raining. Correct If I go for a walk, then it is not raining. It is raining. Therefore, I do not go for a walk.

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-61
SLIDE 61

Correct or Incorrect?

If I go for a walk, then it is not raining. It is not raining. Therefore, I go for a walk. Incorrect If I go for a walk, then it is not raining. I go for a walk. Therefore, it is not raining. Correct If I go for a walk, then it is not raining. It is raining. Therefore, I do not go for a walk. Correct

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-62
SLIDE 62

Correct or Incorrect?

If I go for a walk, then it is not raining. It is not raining. Therefore, I go for a walk. Incorrect If I go for a walk, then it is not raining. I go for a walk. Therefore, it is not raining. Correct If I go for a walk, then it is not raining. It is raining. Therefore, I do not go for a walk. Correct If I go for a walk, then it is not raining. I do not go for a walk. Therefore, it is raining.

Nabil Mustafa CS211A: Discrete Mathematics 1

slide-63
SLIDE 63

Correct or Incorrect?

If I go for a walk, then it is not raining. It is not raining. Therefore, I go for a walk. Incorrect If I go for a walk, then it is not raining. I go for a walk. Therefore, it is not raining. Correct If I go for a walk, then it is not raining. It is raining. Therefore, I do not go for a walk. Correct If I go for a walk, then it is not raining. I do not go for a walk. Therefore, it is raining. Incorrect

Nabil Mustafa CS211A: Discrete Mathematics 1