33
Discrete Mathematics Chapter 2 Propositional Logic Dr.Khaled Bakro 1

Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Embed Size (px)

Citation preview

Page 1: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Discrete Mathematics

Chapter 2

Propositional Logic

Dr.Khaled Bakro 1

Page 2: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional Logic

A proposition is a declarative sentence (a sentence that declares a fact) that is either true or false, but not both.

Are the following sentences propositions?Cairo is the capital of Eygpt. Read this carefully. 1+2=3x+1=2What time is it?

(No)

(No)(No)

(Yes)

(Yes)

Introduction

2

Page 3: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional LogicPropositional Logic – the area of logic that deals

with propositionsPropositional Variables – variables that represent

propositions: p, q, r, s E.g. Proposition p – “Today is Friday.”

Truth values – T, FLogical operators are used to form new

propositions from two or more existing propositions. The logical operators are also called connectives.

3

Page 4: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional Logic

Examples Find the negation of the proposition “Today is Friday.”

DEFINITION 1

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.

Solution: The negation is “It is not the case that today is Friday.” “Today is not Friday.” or “It is not Friday today.” 4

The Truth Table for the Negation of a Proposition.

p ¬pTF

FT

Truth table:

Page 5: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional Logic

Examples Find the conjunction of the propositions p and

q where p is the proposition “Today is Friday.” and q is the proposition “It is raining today.”, and the truth value of the conjunction.

DEFINITION 2

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.

Solution: The conjunction is the proposition “Today is Friday and it is raining today.” The proposition is true on rainy Fridays.

5

The Truth Table for the Conjunction of Two Propositions.p q p Λ q

T T T F F T F F

TFFF

Page 6: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional Logic

Note: inclusive or : The disjunction is true when

at least one of the two propositions is true. E.g. “Students who have taken calculus or

computing essentials can take this class.” – those who take one or both classes.

DEFINITION 3

Let p and q be propositions. The disjunction of p and q, denoted by p ν q, is the proposition “p or q”. The conjunction p ν q is false when both p and q are false and is true otherwise.

6

The Truth Table for the Disjunction of Two Propositions.p q p ν q

T T T F F T F F

TTTF

Page 7: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional Logic

DEFINITION 4

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.

The Truth Table for the Exclusive Or (XOR) of

Two Propositions.p q p q

T T T F F T F F

FTTF

7

exclusive or : The disjunction is true only when one of the proposition is true.

E.g. “Students who have taken calculus or competing essentials, but not both, can take this class.” – only those who take one of them.

Page 8: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional Logic

DEFINITION 5

Let p and q be propositions. The conditional statement p → q, is the proposition “if p, then q.” The conditional statement is false when p is true and q is false, and true otherwise.

Conditional Statements

A conditional statement is also called an implication.

Example: “If I am elected, then I will lower taxes.” p → q implication:elected, lower taxes. T T | Tnot elected, lower taxes. F T | Tnot elected, not lower taxes. F F | Telected, not lower taxes. T F | F

8

p: hypothesis, q: conclusion

Page 9: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional Logic

Example: Let p be the statement “Maria learns discrete mathematics.” and

q the statement “Maria will find a good job.” Express the statement p → q as a statement in English. Solution: Any of the following -

“If Maria learns discrete mathematics, then she will find a good job.

“Maria will find a good job when she learns discrete mathematics.”

“For Maria to get a good job, it is sufficient for her to learn discrete mathematics.”

“Maria will find a good job unless she does not learn discrete mathematics.”

9

Page 10: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional LogicOther conditional statements:

Converse of p → q : q → p Contrapositive of p → q : ¬ q → ¬ p Inverse of p → q : ¬ p → ¬ q

10

Page 11: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional Logic

p ↔ q has the same truth value as (p → q) Λ (q → p) “if and only if” can be expressed by “iff” Example:

Let p be the statement “You can take the flight” and let q be the statement “You buy a ticket.” Then p ↔ q is the statement

“You can take the flight if and only if you buy a ticket.”

Implication:If you buy a ticket you can take the flight.If you don’t buy a ticket you cannot take the flight.

DEFINITION 6

Let p and q be propositions. The biconditional statement p ↔ q is the proposition “p if and only if q.” 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.

11

The Truth Table for the Biconditional p ↔ q.

p q p ↔ q T T T F F T F F

TFFT

Page 12: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional Logic

We can use connectives to build up complicated compound propositions involving any number of propositional variables, then use truth tables to determine the truth value of these compound propositions.

Example: Construct the truth table of the compound proposition

(p ν ¬q) → (p Λ q).

Truth Tables of Compound Propositions

The Truth Table of (p ν ¬q) → (p Λ q).p q ¬q p ν ¬q p Λ q (p ν ¬q) → (p Λ q)

T TT FF TF F

FTFT

TTFT

TFFF

TFTF 12

Page 13: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional Logic

We can use parentheses to specify the order in which logical operators in a compound proposition are to be applied.

To reduce the number of parentheses, the precedence order is defined for logical operators.

In general, 2n rows are required if a compound proposition involves n propositional variables in order to get the combination of all truth values.

Precedence of Logical Operators

Precedence of Logical Operators.Operator Precedence

¬ 1Λ

ν23

→↔

45

E.g. ¬p Λ q = (¬p ) Λ q

p Λ q ν r = (p Λ q ) ν r

p ν q Λ r = p ν (q Λ r)

13

Page 14: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional Logic

Computers represent information using bits. A bit is a symbol with two possible values, 0 and 1. By convention, 1 represents T (true) and 0 represents F (false). A variable is called a Boolean variable if its value is either true or

false. Bit operation – replace true by 1 and false by 0 in logical operations.

Table for the Bit Operators OR, AND, and XOR.x y x ν y x Λ y x y

0011

0101

0111

0001

0110

Logic and Bit Operations

14

Page 15: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional Logic

Example: Find the bitwise OR, bitwise AND, and bitwise XOR of the bit string 01 1011 0110 and 11 0001 1101.

DEFINITION 7

A bit string is a sequence of zero or more bits. The length of this string is the number of bits in the string.

Solution:

01 1011 0110

11 0001 1101 ------------------- 11 1011 1111 bitwise OR

01 0001 0100 bitwise AND10 1010 1011 bitwise XOR

15

Page 16: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional Equivalences

DEFINITION 1

A compound proposition that is always true, no matter what the truth values of the propositions that occurs in it, is called a tautology. A compound proposition that is always false is called a contradiction. A compound proposition that is neither a tautology or a contradiction is called a contingency.

Introduction

Examples of a Tautology and a Contradiction.

p ¬p p ν ¬p p Λ ¬p

TF

FT

TT

FF

16

Page 17: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional Equivalences

DEFINITION 2

The compound propositions p and q are called logically equivalent if p ↔ q is a tautology. The notation p ≡ q denotes that p and q are logically equivalent.

Logical Equivalences

Truth Tables for ¬p ν q and p → q .

p q ¬p ¬p ν q p → q

TTFF

TFTF

FFTT

TFTT

TFTT

Compound propositions that have the same truth values in all possible cases are called logically equivalent. Example: p q and p q are logically equivalent Truth tables are the simplest way to prove such facts. We will learn other ways later. Example Show that ¬p ν q and p → q are logically equivalent.

17

Page 18: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Propositional EquivalencesConstructing New Logical Equivalences

Example: Show that ¬(p → q ) and p Λ ¬q are logically equivalent. Solution:

¬(p → q ) ≡ ¬(¬p ν q) by example on slide 21 ≡ ¬(¬p) Λ ¬q by the second De Morgan law ≡ p Λ ¬q by the double negation law

Example: Show that (p Λ q) → (p ν q) is a tautology.Solution: To show that this statement is a tautology, we will use logical equivalences to demonstrate that it is logically equivalent to T. (p Λ q) → (p ν q) ≡ ¬(p Λ q) ν (p ν q) by example on slide 21

≡ (¬ p ν ¬q) ν (p ν q) by the first De Morgan law ≡ (¬ p ν p) ν (¬ q ν q) by the associative and communicative law for disjunction ≡ T ν T ≡ T

Note: The above examples can also be done using truth tables. 18

Page 19: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Compound PropositionsNegation (not) pConjunction (and) p qDisjunction (or)p qExclusive or p qImplication p qBiconditional p qConverse q pContrapositive q pInverse p q

Page 20: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

De Morgan’s Laws

(p q) p q (p q) p q

What are the negations of:Casey has a laptop and Jena has an iPod

Clinton will win Iowa or New Hampshire

Page 21: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Equivalences relating to implication

p q p qp q q pp q p qp q (p q)p q (p q) (q p)p q p qp q (p q) ( p q) (p q) p q

Page 22: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Tautology

A compound proposition that is always TRUE, e.g. q q

Logical equivalence redefined: p,q are logical equivalences if p q is a tautology. Symbolically p q.

Intuition: p q is true precisely when p,q have the same truth values.

22

Page 23: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Distributive Lawsp (q r) (p q) (p r) Intuition (not a proof!) – For the LHS to be true: p must

be true and q or r must be true. This is the same as saying p and q must be true or p and r must be true.

p (q r) (p q) (p r) Intuition (less obvious) – For the LHS to be true: p must

be true or both q and r must be true. This is the same as saying p or q must be true and p or r must be true.

Proof: use truth tables.

23

Page 24: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Predicate LogicA predicate is a proposition that is a

function of one or more variables. E.g.: P(x): x is an even number. So P(1)

is false, P(2) is true,….Examples of predicates:

Domain ASCII characters - IsAlpha(x) : TRUE iff x is an alphabetical character.

Domain floating point numbers - IsInt(x): TRUE iff x is an integer.

Domain integers: Prime(x) - TRUE if x is prime, FALSE otherwise.

24

Page 25: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Quantifiers

describes the values of a variable that make the predicate true. E.g. x P(x)

Domain or universe: range of values of a variable (sometimes implicit)

25

Page 26: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Two Popular QuantifiersUniversal: x P(x) – “P(x) for all x in the

domain”Existential: x P(x) – “P(x) for some x in

the domain” or “there exists x such that P(x) is TRUE”.

Either is meaningless if the domain is not known/specified.

Examples (domain real numbers)x (x2 >= 0)x (x >1)(x>1) (x2 > x) – quantifier with restricted domain

26

Page 27: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Using Quantifiers

Domain integers:Using implications: The cube of all

negative integers is negative. x (x < 0) (x3 < 0) Expressing sums : n

n ( i = n(n+1)/2) i=1

27

Aside: summation notation

Page 28: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Scope of Quantifiers have higher precedence than

operators from Propositional Logic; so x P(x) Q(x) is not logically equivalent to x (P(x) Q(x))

x (P(x) Q(x)) x R(x) Say P(x): x is odd, Q(x): x is divisible by 3, R(x): (x=0) (2x >x)

Logical Equivalence: P Q iff they have same truth value no matter which domain is used and no matter which predicates are assigned to predicate variables.

28

Page 29: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Statements with quantifiers

• x Even(x)

• x Odd(x)

• x (Even(x) Odd(x))

• x (Even(x) Odd(x))

• x Greater(x+1, x)

• x (Even(x) Prime(x))

Even(x)Odd(x)Prime(x)Greater(x,y)Equal(x,y)

Domain:Positive Integers

Page 30: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Negation of Quantifiers“There is no student who can …”“Not all professors are bad….”“There is no Toronto Raptor that can

dunk like Vince …” x P(x) x P(x) why?

x P(x) x P(x)Careful: The negation of “Every Canadian

loves Hockey” is NOT “No Canadian loves Hockey”! Many, many students make this mistake!

30

Page 31: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Nested QuantifiersAllows simultaneous quantification of

many variables. E.g. – domain integers, x y z x2 + y2 = z2 n x y z xn + yn = zn (Fermat’s

Last Theorem)Domain real numbers: x y z (x < z < y) (y < z < x)

31

Is this true?

Page 32: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Nested Quantifiers - 2x y (x + y = 0) is true over the integersAssume an arbitrary integer x.To show that there exists a y that satisfies

the requirement of the predicate, choose y = -x. Clearly y is an integer, and thus is in the domain.

So x + y = x + (-x) = x – x = 0.Since we assumed nothing about x (other

than it is an integer), the argument holds for any integer x.

Therefore, the predicate is TRUE.32

Page 33: Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو

Nested Quantifiers - 3Caveat: In general, order matters!

Consider the following propositions over the integer domain:

x y (x < y) and y x (x < y) x y (x < y) : “there is no maximum

integer”y x (x < y) : “there is a maximum

integer”Not the same meaning at all!!!

33