43
CS104 The Foundations: Logic and Proof 1

The Foundations: Logic and Proof

Embed Size (px)

DESCRIPTION

The Foundations: Logic and Proof. CS104. 1.3 Propositional Equivalences. Introduction Logical Equivalences. Introduction. Definition1 A compound proposition that is always true, no matter what the truth values of the propositions that occurs in it, is called a tautology. - PowerPoint PPT Presentation

Citation preview

Page 1: The Foundations: Logic and Proof

CS104

The Foundations: Logic and Proof

1

Page 2: The Foundations: Logic and Proof

1.3 Propositional Equivalences

•Introduction •Logical Equivalences

2

Page 3: The Foundations: Logic and Proof

Introduction Definition1 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.

3

ppp p p p

FTTF

TFTF

Page 4: The Foundations: Logic and Proof

Logic Equivalence Definition2:

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.

4

•Compound propositions that have the same truth values in allpossible cases are called logically equivalent.

Example: Show that ¬(p ν q) and p q are logically equivalent.

pqp q(p q)pqp q

FTFT

FFTT

FTTT

TFFF

TFTF

TTFF

TFFF

De Morgan’s

Laws

Page 5: The Foundations: Logic and Proof

Logic Equivalence

5

• Example3:Show that ¬p ν q and p → q are logically

equivalent.

Solution on the book

Show that p (q r) (p q) (p r)

Page 6: The Foundations: Logic and Proof

Logic Equivalence

6

EquivalenceName

p Λ T p and p ν F pIdentity laws

p ν T T and p Λ F FDomination laws

p ν p p and p Λ p pIdempotent laws

¬( ¬ p) pDouble negation

law

p ν q q ν p and p Λ q q Λ pCommutative

laws

(p ν q) ν r p ν (q ν r) and (p Λ q) Λ r p Λ (q Λ r)

Associative laws

p (q r) (p q) (p r)p (q r) (p q) (p r) Distributive laws

¬(p ν q) ¬p Λ ¬q and ¬(p Λ q) ¬p ν ¬qDe Morgan’s laws

p (p q) p and p (p q) pAbsorption laws

p ν ¬p T and p Λ ¬p FNegation laws

Page 7: The Foundations: Logic and Proof

Logic Equivalence

7

Page 8: The Foundations: Logic and Proof

Logic EquivalenceExample6: Show that ¬(p → q ) and p Λ ¬q are logically equivalent.

Solution:

¬(p → q ) ≡ ¬(¬p ν q)

≡ ¬(¬p) Λ ¬q by the second De Morgan law

≡ p Λ ¬q by the double negation law

Example8: 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)

≡ (¬ 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.

8

Page 9: The Foundations: Logic and Proof

1.4 Predicates and Quantifiers

•Introduction •Predicates•Quantifiers •Universal quantifier•Quantifier with restricted domains•Logical equivalences involving quantifiers•Negating quantified expressions•Translating from English into logical expressions9

Page 10: The Foundations: Logic and Proof

Predicates and Quantifiers

• Propositional logic cannot adequately express the meaning of

all statements in mathematics and natural language !

e.g. we know that : “ every computer connected to the

network is

functioning properly “ ,

• Predicate Logic :

is a powerful type of logic that could be used to express the

meaning of wide range of statements in mathematics and CS.

• Two main concepts are introduced:

Predicate

Quantifiers.

10

Page 11: The Foundations: Logic and Proof

Predicates and Quantifiers• Predicate:

• Statements involving variables such as : x > 3, x = y + 3 , x + y =

z are neither True nor false when the value of variables are not

specified.

• This section discusses how proposition can be produced from such

statements

• The statement x>3 has two parts :

the first part: subject of statement ,variable x

the second part: predicate , a property that the subject of a

statement

can have , “ is greater than 3”

• The statement could be denoted by : P(x) , propositional

function ,where p is a predicate(is greater than 3), x is a variable.

• Once we assign a value to variable x, P(x) becomes a proposition

that could be True or False.11

Page 12: The Foundations: Logic and Proof

Predicates

12

• Example:

Let P(x) : x > 3 , what is the truth value of P(4) ?

setting x = 4 , 4 > 3 , true

Let P (x,y) : x = y + 3, what is the truth value of P(1,2) , “ involve

more than one variable ! “

1 = 2 + 3 , false

• A statement of the form P(x1, x2, …., xn) is the value of the

propositional function P at the n-tuple (x1, x2, …., xn) and P is

called n-ary predicate

• Propositional function occurs in computer programs as in the

following example.

Page 13: The Foundations: Logic and Proof

PredicatesExample:

Consider the statement

if x > 0 then x := x + 1.

Here P(x) = “x > 0”.

If P(x) is true for the value of x, then the

assignment statement x := x + 1 is executed, x is

increased by 1.

If P(x) is false for the value of x, then the

assignment statement is not executed, x remains same

13

Page 14: The Foundations: Logic and Proof

Predicates

14

Usage of Predicate:

•Predicate are used to establish the correctness of

computer program, i.e. to show that computer programs

always produce the desired output when given valid input.

•Precondition: statements that describe valid input

•Postcondition: condition that the output should satisfy

when the program has run

Page 15: The Foundations: Logic and Proof

PredicatesExample:

The following code is designed to interchange the values

of two variables x and y:

The predicate for precondition:

P (x ,y) where P (x , y) is x = a , y = b

The predicate for postcondition:

Q ( x , y) where Q ( x , y) is x = b , y = a

15

temp := xx := y y := temp

Page 16: The Foundations: Logic and Proof

Quantifiers

16

Quantification :

•It is a way to create a proposition from a propositional

function.

•It expresses the extent to which a predicate is true over a

range of elements.

•In English, the words all, some , many, none and few are

used in quantification.

Types of Quantification:

1.Universal quantification: Which tells that a predicate is

true for every element under consideration.

2. Existential quantification: Which tells that there is one

or more element under consideration for which the

predicate is true.

Page 17: The Foundations: Logic and Proof

Universal Quantifiers

Universal Quantifiers:

•Many mathematical statements assert that a property is true

for all values of a variable in a particular domain.

•The universal quantification of P(x) for particular domain is

the statement “P(x) is true for all values of x in the domain”.

•The notation x P(x) denotes the universal quantification of

P(x). Here is called universal quantifier.

•The meaning of the universal quantification of P(x) changes

when the domain is changed.

•An element for which P(x) is false is called a counterexample

of x P(x).

17

Page 18: The Foundations: Logic and Proof

Universal Quantifiers

18

Example:

Let P(x) = “x+1 > x”. What is the truth value of the quantification

x P(x), where the domain consists of all real numbers?

Because P(x) is true for all real numbers x, the quantification x

P(x) is true.

Example:

Let Q(x) = “x < 2”. What is the truth value of the quantification x

Q(x), where the domain consists of all real numbers?

Because Q(x) is not true for every real number x, because, for

instance, Q(3) is false. That is, x=3 is a counterexample for the

statement x Q(x).

Page 19: The Foundations: Logic and Proof

Universal Quantifiers

19

Page 20: The Foundations: Logic and Proof

Existential Quantifiers

20

Existential Quantifier

•Many mathematical statements assert that there is an

element with a certain property.

•The existential quantification of P(x) is the statement

“There exists an element x in the domain such that P(x)”.

•The notation x P(x) denotes the existential quantification

of P(x). Here is called existential quantifier.

Page 21: The Foundations: Logic and Proof

Existential Quantifiers

21

Example:

Let P(x) = “x > 3”. What is the truth value of the

quantification x P(x), where the domain consists of all real

numbers?

Because P(x) is sometimes true - for instance, when x=4 –

the existential quantification of P(x), which is x P(x), is

true.

Example:

Let P(x) = “x = x+1”. What is the truth value of the

quantification x P(x), where the domain consists of all real

numbers?

Because P(x) is false for every real number x, the

quantification x P(x) is false.

Page 22: The Foundations: Logic and Proof

Predicates and Quantifiers

Page 23: The Foundations: Logic and Proof

Predicates and Quantifiers

23

Page 24: The Foundations: Logic and Proof

Translating English Sentences

24

Page 25: The Foundations: Logic and Proof

Translating English into Logical Expression

25

• Translating from English to logical expression becomes

even more complex when quantifiers are needed ! , and it

could be done in four main steps:

1. Determine the quantifier used in the sentence

2. Determine the variable in the sentence

3. Determine the domain of this variable

4. Determine the predicate

5. Write complete sentence

Page 26: The Foundations: Logic and Proof

Translating English into Logical Expression

26

Page 27: The Foundations: Logic and Proof

Translating English into Logical Expression

Page 28: The Foundations: Logic and Proof

Quantifiers with Restricted Domains

28

Quantifiers with Restricted Domains:

•An abbreviated notation is used to restrict the domain of a quantifier.

In this notation, a condition, a variable must satisfy, is included after

the quantifier.

•The restriction of a universal quantification is the same as the

universal quantification of a conditional statement.

For instance, x < 0(x2 > 0) is another way of expressing x (x <

0 → x2 > 0).

•The restriction of an existential quantification is the same as the

existential quantification of a conjunction.

For instance, z>0 (z2=2) can be expressed as z (z > 0 ˄ z2 = 2).

Page 29: The Foundations: Logic and Proof

Quantifiers with Restricted Domains

Example:

What do the statement x < 0(x2 > 0), and z > 0(z2 = 2) mean?

The statement x < 0(x2 > 0) states that for every number x with x <

0, x2 > 0.

That is, it states “The square of a negative real number is positive”.

The statement is the same as x (x < 0 → x2 > 0).

The statement z > 0(z2 = 2) states that there exist a real number z

with z > 0 such

that z2=2.

That is, it states “There is positive square root of 2”.

The statement is the same as z (z > 0 ˄z2 = 2).

29

Page 30: The Foundations: Logic and Proof

Logical Equivalences Involving QuantifiersPrecedence of Quantifiers:

• The quantifiers and have higher precedence then all logical operators

from propositional calculus.

• For example, xP(x) v Q(x) is the disjunction of xP(x) and Q(x). In other

words, it means (xP(x)) v Q(x) rather than x (P(x) v Q(x))

Logical Equivalences Involving Quantifiers:

Statements involving predicate and quantifiers are logically equivalent if and

only

if they have the same truth value no matter which predicates are substituted

into

these statements and which domain of discourse is used for the variables in

these

propositional functions.

30

Page 31: The Foundations: Logic and Proof

Logical Equivalences Involving QuantifiersExample:

Show that x (P(x) Q(x)) and xP(x) x Q(x) are logically

equivalent.

Let x (P(x) Q(x)) is true

=> if a is in the domain, then P(a) Q(a) is true

=> P(a) and Q(a) are true, for all a in the domain

=> xP(x) and xQ(x) are true

=> xP(x) xQ(x) is true

So, they are logically equivalent.

31

Page 32: The Foundations: Logic and Proof

Negation Quantified ExpressionExample: “Every student in your class has

taken a course in calculus”Domain consists of the students in your class.P(x) is the statement “x has taken a course in

calculus”x P(x).Negation of the statement: “It is not the case

that every student in your class has taken a course in calculus”. This equivalent to “There is a student in your class who has not taken a course in calculus”.

This is simply the existential quantification x P(x) .

32

Page 33: The Foundations: Logic and Proof

Negation Quantified Expression

33

De Morgan’s laws for quantifiers

Example:

Show that x(P(x)Q(x)) and x(P(x) Q(x)) are logically

equivalent.

Page 34: The Foundations: Logic and Proof

1.5 Nested Quantifiers

•Introduction•Order of quantifiers•Translating mathematical statements into statements involving nested quantifiers•Translating from nested quantifiers into English

34

Page 35: The Foundations: Logic and Proof

35

Nested Quantifiers

• Two quantifiers are said to be nested if one is within the scope of the

other, such as x y (x + y = 0)

o Note that xy (x + y = 0) is same as x Q(x), where Q(x) is yP(x,

y), where P(x, y) is x + y = 0.

o It says that for every real number x there is a real number y such

that x + y = 0. This states that every real number has an additive

inverse.

Page 36: The Foundations: Logic and Proof

Nested Quantifiers

Example:

Assume that the domain for the variables x and y consists of all real

numbers.

•The statement : xy (x + y = y + x)

says that x + y = y + x for all real numbers x and y. This is commutative

law for addition of real numbers.

• The statement : xyz (x + (y + z) = (x + y) + z) is associative law for

addition of real numbers.

Page 37: The Foundations: Logic and Proof

37

Nested Quantifiers• The order of the quantifiers is important unless all the quantifiers are universal

quantifiers or all are existential quantifiers.

Example:

Let P(x, y) be the statement “x + y = y + x”. What are the truth values of the

quantifications xyP(x, y) and yxP(x, y), where the domain for all variables

consists of all real numbers?

The quantification xyP(x, y) is the proposition “For all real numbers x, for all real

numbers y, x + y = y + x”. Since P(x, y) is true for all real numbers x and y, the

proposition xyP(x, y) is also true.

Also, yxP(x, y) is the proposition “For all real numbers y, for all real numbers x, x

+ y = y + x” = xyP(x, y), so it is true.

Page 38: The Foundations: Logic and Proof

38

Nested Quantifiers

Note: Order of nested universal quantifiers in a statement without other quantifiers

can be changed without changing meaning of quantified statement.

Example:

Let Q(x, y) be the statement “x + y = 0”. What are the truth values of the

quantifications yxQ(x, y) and xyQ(x, y), where the domain for all variables

consists of all real numbers?

•yxQ(x, y) = “There is a real number y such that for every real number x, x + y

= 0”. Since there is no real number y such that x + y = 0, for all real numbers x,

the proposition yxQ(x, y) is false.

•xyQ(x, y) = “For every real number x, there is a real number y such that x + y

= 0”. Given a real number x, there is a real number y, namely y = -x, such that x +

y =0. So, xyQ(x, y) is true.

Page 39: The Foundations: Logic and Proof

39

Statement

When True?When False?

xyP(x, y)yxP(x, y)

P(x, y) is true for every pair x, y.

There is a pair x, y for which P(x, y) is false

xyP(x, y),

For every x there is a y for which P(x, y) is true

There is an x such that P(x, y) is false for every y

xyP(x, y)

There is an x such that P(x, y) is true for every y

For every x there is a y for which P(x, y) is false

xyP(x, y)yxP(x, y)

There is a pair x, y for which P(x, y) is true

P(x, y) is false for every pair x, y.

Nested Quantifiers

The following table summarizes the meanings of the different possible

quantifications involving two variables:

Page 40: The Foundations: Logic and Proof

40

Nested Quantifiers

Example:

Let Q(x, y, z) be the statement “x + y = z”. What are the truth values of the

quantifications xyzQ(x, y, z) and zxyQ(x, y, z), where the domain

for all variables consists of all real numbers?

xyzQ(x, y, z) = “For all real numbers x and for all real numbers y there

is a real number z such that x + y = z” is true.

The order of quantification is important here. Since zxyQ(x, y, z) =

“There is a real number z such that for all real numbers x and for all real

numbers y, x + y = z”, is false, because there is no z that satisfies th

equation x + y = z for all for all real numbers x and y

Page 41: The Foundations: Logic and Proof

41

Nested Quantifiers

Example: Translate the statement “The sum of two positive integers is

always positive” into a logical expression.

Let x and y be two positive integers, then we can write the statement as

“For all positive integers x and y, x + y is positive”

• Determine the quantifier used in the sentence : universal

• Determine the variable in the sentence: x and y

• Determine the domain of this variable : positive integers

• Determine the predicate: p(x,y) is “ x + y >0 “

• Write complete sentence : xy (x + y > 0)

Also, it can be expressed as xy((x > 0) ⌃ (y > 0) → (x + y > 0)) where

the domain for both variables consists of integers.

Page 42: The Foundations: Logic and Proof

42

Nested Quantifiers

Example: Translate the statement “Every real number except zero has a

multiplicative inverse” into a logical expression.

Example: Translate the statement x(C(x) v y(C(y) F⌃ (x, y)))

into English, where C(x)=“x has a computer”, F(x, y) = “x and y are

friends”, and the domain for both x and y consists of all students in your class.

The statement says that for every student x in your class, x has a computer or

there is a student y such that y has computer and x and y are friends.

In other words, every student in your class has a computer or has a friend who

has a computer.

Page 43: The Foundations: Logic and Proof

Nested Quantifiers

Example:

Translate the statement xyz((F(x, y) F⌃ (x, z) (y ≠ z)) → ⌃ F(y, z))

into English, where F(a, b) means a and b are friends and the domain for x, y and

consists of all students in your class.