47
1 Limitations of Propositional Logic Which can NOT be expressed using propositional logic? Ex1: How do you make a statement about all even integers from integers? (any x, x mod 2 = 0) Ex2: Every computer connected to the university network is functioning properly, which can imply () CS1 is functioning properly. A more general language: Predicate logic 2019/9/10 CSE, NCHU

Limitations of Propositional Logic

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

1

Limitations of Propositional Logic

◼ Which can NOT be expressed using propositional logic?

Ex1: How do you make a statement about all even integers from integers? (any x, x mod 2 = 0)

Ex2: Every computer connected to the university network is functioning properly,

which can imply (➔) CS1 is functioning

properly.

◼ A more general language: Predicate logic

2019/9/10 CSE, NCHU

2

Predicate Logic (1/3)

Predicate Calculus or Predicate Logic• Predicate – refers to a property that the subject

of a statement can have.• The area of logic that deals with predicates and

quantifiers (e.g. for any and there exists )E.G. “x is greater than 3”

x is the subject and “is greater than 3” is a predicate.

• A predicate which binds with variable(s) is called propositional function.

2019/9/10 CSE, NCHU

3

Predicate Logic (2/3)

◼ Propositional function P at x, P(x), once a value has been assigned to x, P(x) becomes a proposition and has a truth value. Domain of x is critical.

E.g. P(x)=x2, “P(x) is even → x is even” is true if Domain(x) = Z, and it is false if domain(x) = R.

◼ Examples of predicates:◼ Domain is ASCII characters - IsAlpha(x) is TRUE

iff x is an alphabetical character.

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

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

2019/9/10 CSE, NCHU

◼ A propositional function may associate with two or more variables.

Eg 1: P(x,y): “x = y+3”, and P(1,2) is false.

Eg 2: Q(x,y,z): “x+y=z”, then Q(1,2,3) is true.

◼ P(x1, x2, …, xn ) is the value of the propositional function P at the n-tuple (x1, x2, …, xn ) and P is also called a n-tuple predicate or a n-ary predicate. (uniary, binary, ternary, quad…)

4

Predicate Logic (3/3)

2019/9/10 CSE, NCHU

◼ Consider the following program,temp := x

x := y

y := temp

◼ Let the precondition P(x,y) be “x=a and y=b”

the postcondition Q(x,y) be “x=b and y=a”

after (temp := x), we get x=a, temp=a, y=b

after (x := y), we get x=b, temp=a, y=b

after (y :=temp), we have x=b, temp=a, y=a

This has verified the correctness of the program.

5

Preconditions and Postconditions

2019/9/10 CSE, NCHU

6

Quantifications

◆ When the variables in a propositional function are assigned values, the resulting statement becomes a proposition, which could be either true of false.

◆ Another way to create a proposition – using

Quantifications

◆ Universal quantification

◆ Existential quantification

◆ Uniqueness quantification !2019/9/10 CSE, NCHU

7

Two Popular Quantifiers

◼ Universal: 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. Think about x (x2 ≧ x) ?

◼ Examples

◼ x (x2 ≧ 0) is true, if domain of x is R.

◼ x (x >1) is true, if domain of x is R.

◼ (x>1) (x2 > x) is true, if domain of x is R.

Note: in the last case - quantifier with restricted domain2019/9/10 CSE, NCHU

8

Using Quantifiers

Let domain of x be integers,◼ Using implications: The cube of any

negative integer is negative. x (x < 0) →(x3 < 0)

◼ Expressing sums (domain of n is N):

n

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

2019/9/10 CSE, NCHU

9

Scope of Quantifiers

◼ , have higher precedence than operators from Propositional Logic (¬ → )

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(x) Q(x) iff they have same truth value no matter which domain value is used and no matter which predicates are substituted into these statements.

◼ For example, ¬x P(x) x ¬P(x) 2019/9/10 CSE, NCHU

10

Logical Equivalence Involving Quantifiers

◼ Logical Equivalence: P(x) Q(x) iff they have same truth value no matter which domain value is used and no matter which predicates are substituted into these statements.

◼ E.g.1 ¬x P(x) x ¬P(x)

◼ E.g.2 x (P(x) Q(x)) x P(x) x Q(x)

◼ E.g.3 x (P(x) Q(x)) x P(x) x Q(x)

Notice that we can not distribute universal quantifier over a disjunction , nor can we distribute an existential quantifier over a conjunction .

2019/9/10 CSE, NCHU

11

Translation Examples (1/5)

Example 23: “Every student in this class has studied calculus.”

Sol_1:Domain(x)={the students in this class}

C(x) represents “x has studied calculus”

x C(x)

Sol_2:Domain(x)={all people}S(x) stands for “the person x is in this class”

x (S(x) → C(x)) (Caution: Not x (S(x) C(x)) )

Sol_3: Domain(x)={the students in this class} or {all people} Q(x,y) represents “x has studied subject y”

x Q(x, calculus) or x (S(x) → Q(x, calculus))

2019/9/10 CSE, NCHU

12

Translation Examples (2/5)

Example 24: “some student in this class has visited Mexico” and “every student in this class has visited either Canada or Mexico”

Sol: Let M(x) = “x has visited Mexico”

S(x) = “x is a student in this class”

C(x) = “x has visited Canada”

V(x,y) denotes “x has visited y”

x M(x) if x’s domain is {the students in this class}

X (S(x) M(x)) if x’s domain is defined as {all people}

(Caution: not X (S(x) → M(x)) Why? )x (S(x) → (C(x) M(x)) or x (S(x) → (V(x,Mexico) V(x,Canada)))

if x’s domain is defined as {all people}, how about in the restricted domain?

2019/9/10 CSE, NCHU

13

Supplement to E.G. 24

(i) “some student in this class has visited Mexico” and

(ii) “every student in this class has visited Mexico”

Let M(x) = “x has visited Mexico”

S(x) = “x is a student in this class”

Assume that Domain(x)={all people}

(i) x (S(x) M(x))

(Caution: not x (S(x) → M(x)) Why? 存在外人造訪M,擴大解釋)

If domain is the students in the class,上述也多此一舉,畫蛇添足(ii) x (S(x) → M(x))

擴大解釋之嫌? x (S(x) is false means nonsense assumption, not false assumption.

假如我有500萬,假如我是總統,假如所有人都是鳥。。。有差異

2019/9/10 CSE, NCHU

14

Translation Examples (3/5)

Translation from English into logical expression

• Every student in this class has studied calculus

C(x): x has studied calculus

S(x): the person x is in this class

Q(x,y): student x has studied subject y

x (S(x) → C(x)), Domain(x)={students in the class}

or

x (S(x) → Q(x, calculus)), Domain(x)={all people}

x Q(x, calculus)

2019/9/10 CSE, NCHU

15

Translation Examples (4/5)Examples from Lewis Carroll1. all lions are fierce 2. some lions do not drink coffee3. some fierce creatures do not drink coffee1&2 are premises, 3 is called the conclusion.The entire set is called an argument.

P(x): x is a lionQ(x): x is fierceR(x): x drinks coffee

1. x (P(x) → Q(x))

2. x (P(x) ¬R(x)) (note: not x (P(x) → ¬ R(x))

3. x (Q(x) ¬R(x)) (note: not x (Q(x) → ¬ R(x))

2019/9/10 CSE, NCHU

16

Translation Examples (5/5)Use predicates and quantifiers to express the system specifications. “Every mail messages larger than one megabytes will be compressed” and “If a user is active, at least one network link will be available.”

Let S(m,y) be “mail message m is larger than y megabytes”, where domain(m) is {all messages} and domain(y) is {positive integers}. C(m) denotes “mail message m will be compressed”, domain(m) is {all messages}.

Let A(u) be “user u is active”, where domain(u) is {all users}. Let S(n,x) be “network link n is in state x”, domain(n) is {all network links} and domain(x) is {all possible states for a network link}.

1. m (S(m,1) → C(m))

2. u A(u) → n S(n, available)

2019/9/10 CSE, NCHU

17

Translation Examples Again (1/2)Let S(x) be “x is a student”, F(x) be “x is a faculty member”, and A(x,y)be “x has asked y a question” where the domain consists of all people.

(expressions in red are for domain of students and faculty members)

✓ Some student has not asked any faculty member a question.

x y (S(x) F(y) ¬A(x,y)) (wrong ?), x y ¬(A(x,y))

x y (S(x) (F(y) → ¬A(x,y))

✓ Some student has asked any faculty member a question.

x y (S(x) F(y) A(x,y)) (wrong ?), x y (A(x,y))

x y (S(x) (F(y) → A(x,y)))

✓ There is a faculty member who has never been asked a question by a student.

y x (F(y) S(x) ¬A(x,y))(wrong ?)) , y x ¬(A(x,y))

y (F(y) x ( S(x) → ¬A(x,y)))

✓ No student has asked all faculty members.

¬(x y (S(x) (F(y) → A(x,y))), ¬(x y (A(x,y)))

2019/9/10

18

Translation Examples Again (2/2)Let S(x) be “x is a student”, F(x) be “x is a faculty member”, and A(x,y) be “x has asked y a question” where the domain consists of all people.

(expressions in red are for domain of students and faculty members)

✓ Every student has asked a faculty member a question.

x (S(x) → y (F(y) (A(x,y))), x y A(x,y)

✓ Every student has asked Professor Gross a question.

x (S(x) → A(x, Prof. Gross)), x A(x, Prof. Gross)

✓ No student has asked Professor Gross a question.

¬(x (S(x) (A(x, Prof. Gross)))), x(¬A(x, Prof. Gross))

✓ No student has asked any faculty member a question.

¬(xy(S(x)(F(y) → A(x,y)))), xy(¬A(x, y))

xy(¬S(x)(F(y)¬A(x,y))) but xy(S(x)F(y)¬A(x,y)) no

2019/9/10 CSE, NCHU

19

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?

E.g. Every student in this class is working hard.

◼ ¬ 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!

2019/9/10 CSE, NCHU

20

Nested Quantifiers (1/3)

◼ Allows simultaneous quantification of many variables.

◼ E.g. Let domains be positive integers,

x y z x2 + y2 = z2 (畢氏定理)

n x y z xn + yn = zn ? false

(對任一n,存在x,y,z 使得xn + yn = zn成立?)

◼ Domain of real numbers:

x y z (x < z < y) (y < z < x) T or F ?

2019/9/10 CSE, NCHU

21

Nested Quantifiers (2/3)

x y (x + y = 0) is true over the integers

◼ Assume x is an arbitrary integer.

◼ 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.

◼ BUT, x y (x + y = 0) is false over the reals

(How about if the domain is “integers”? false)2019/9/10 CSE, NCHU

22

Nested Quantifiers (3/3)

◼ Caveat: 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!!!

2019/9/10 CSE, NCHU

23

Negation of Nested Quantifiers

◼ Use the same rule as before carefully.

◼ Ex 1: ¬x y (x + y = 0) over domain R.

◼ This is equivalent to x ¬y (x + y = 0)

◼ This is equivalent to x y ¬(x + y = 0)

◼ This is equivalent to x y (x + y 0)

◼ Ex 2: ¬x y (x < y) over domain R.

◼ This is equivalent to x ¬y (x < y)

◼ This is equivalent to x y ¬(x < y)

◼ This is equivalent to x y (x y)

2019/9/10 CSE, NCHU

24

Translation Examples (1/4)

Example 7: “Every real number except 0 has a multiplicative inverse.”

Sol:Assume that the domains of x and y are all “real numbers”

Let’s rewrite the sentence as “For every real number x except 0, x has a multiplicative inverse.”

x ((x ≠ 0) → y (xy = 1))

2019/9/10 CSE, NCHU

25

Translation Examples (2/4)Example 8: use quantifiers to express the definition of limit

of a real-valued function f(x) of a real variable at a point a in its domain.

Sol:The definition of the statement lim f(x) = L is: For every real number ε >0 there exists a real number σ>0 such that \f(x)-L\ < ε whenever 0 < \x-a\ < σ. Hence, ε σ x ((0 < \x-a\ < σ) → \f(x)-L\ < ε ) if the domain of ε and σ is all positive reals and domain of x is reals. Or,ε>0 σ>0 x ((0 < \x-a\ < σ) → \f(x)-L\ < ε ), if the domain for ε ,σ, and x is reals.

2019/9/10 CSE, NCHU

26

Translation Examples (3/4)Example 13: There is a woman who has taken a flight on every

airline in the world.

Sol Let P(w,f) be “w has taken f” and

Q(f,a) be “f is a flight on a” The statement can be expressed as w a f (P(w,f) Q(f,a)), where the domains for w,f, and a consists of all the women in the world, all airplane flights, and all airlines, respectively.

Example 15: There does not exist a woman who has taken a flight on every airline in the world.

w ¬a f (P(w,f) Q(f,a)) =w a ¬f (P(w,f) Q(f,a)) =w a f ¬(P(w,f) Q(f,a))

2019/9/10 CSE, NCHU

27

Translation Examples (4/4)

Example 12: Everyone has exactly one best friend.

Sol: Let B(x,y) be “y is the best friend of x” and the domain is all people. The statement can be expressed as

x y (B(x,y) z (B(x,z) → (z = y))), orx y (B(x,y) z ((z ≠ y) → ¬B(x,z))), or x !y (B(x,y)

Q: How about “Someone has no any (best) friend”?x y ¬B(x,y)

2019/9/10 CSE, NCHU

28

Translating into English (1/2)

Example 9: Translate the statement

x (C(x) y(C(y) F(x,y))) into English

where C(x) is “x has a computer. F(x,y) is ”x and y are friends”. The domain of both x and y consists of all students in your school.

A: Every student in your school has a computer or has a friend who has a computer.

2019/9/10 CSE, NCHU

29

Translating into English (2/2)

Example 5: x y z Q(x,y,z) and z x y Q(x,y,z)where Q(x,y,z) is “x+y=z” and the domain of all variables consists of all real numbers.

A: (1) for all real numbers x and for all real numbers y,there is a real number z such that x+y=z. (T)

(2) There is a real number z such that for all real numbers x and for all real numbers y, x+y=z. (F)

2019/9/10 CSE, NCHU

30

Domain is the Matter

Example 6: Translate the statement “the sum of two positive integer is always positive.”

A: (1) Assume the domain of variables is Z. x y ((x>0) (y>0) → (x+y > 0))

(2) Assume that the domain of variable is Z+.x y (x+y > 0)

2019/9/10 CSE, NCHU

31

Argument and Argument form◆ An argument in propositional logic is a sequence of

propositions, or a sequence of statements that end with a conclusion.

◆ For example, “ If you have a current password, then you can log on to the network”., “You have a current password.”, and “You can log onto the network.”

◆ All but the final proposition in the argument are called premises, the final proposition is called the conclusion.

◆ An argument form in propositional logic is a sequence of compound propositions involving propositional variables.

◆ Valid argument means the conclusion must follow from the truth of the premises (no matter which variables are binding to the propositional functions).

2019/9/10 CSE, NCHU

32

Valid Argument

◆ If you have a current password, then you can log onto the network

◆ p “you have a current password”

q “you can log onto the network”

p → q

p

q (means “therefore”)

2019/9/10 CSE, NCHU

33

Valid Argument

◆ The argument form with premises p1, p2, …, pn and conclusion q1 is valid

when

(p1˄ p2˄… ˄ pn) → q is a tautology

2019/9/10 CSE, NCHU

34

Inference rules (1/3)

◆ Recall that the reason for studying logic was to

formalize derivations and proofs.

◆ How can we infer facts using logic?

◆ Simplest possible inference: From p → q and p is

TRUE, we can infer that q is TRUE. (Modus Ponens)

◆ Similarly, From p → q, q → r and p is TRUE, we

can infer that r is TRUE. (by Hypothetical syllogism

& Modus Ponens)

◆ Read rules on page 72 and page 76.

2019/9/10 CSE, NCHU

35

Inference rules (2/3)

◆ Modus ponens (p (p → q)) → q

◆ Modus tollens (¬ q (p → q)) → ¬p

◆ Hypothetical syllogism

((p → q) (q → r)) → (p → r)

◆ Disjunctive syllogism ((p q) ¬p) → q

◆ Addition p → (p q)

◆ Simplification (p q) → p

◆ Conjunction ((p) (q)) → (p q)

◆ Resolution (p q) (¬p r) → (q r)2019/9/10 CSE, NCHU

36

Inference rules (3/3)

◆ Universal instantiation

x P(x) → P(c) for any element c

◆ Universal generalization

P(c) for an arbitrary c → x P(x)

◆ Existential instantiation

x P(x) → P(c) for some element c

◆ Existential generalization

P(c) for some element c → x P(x)

2019/9/10 CSE, NCHU

37

Using Rules of Inference to build Arguments

• Using rules of inference to build arguments:

It is not sunny this afternoon and it is colder than yesterday.We will go swimming only if it is sunny. If we do not go swimming, then we will take a canoe trip. If we take a canoe trip, then we will be home by sunset.

• The conclusion is “we will be home by sunset”

p: It is sunny this afternoonq: it is colder than yesterdayr: we will go swimmings: we will take a canoe tript: we will be home by sunset(1) ¬ p q → ¬ p simplification(2) r → p → ¬ r modus tollens(3) ¬ r → s → s modus ponens(4) s → t → t modus ponens

2019/9/10 CSE, NCHU

38

Literal, Clause, and Resolution

◆ A variable or negation of a variable is called a literal.

◆ A disjunction of literals is called a sum and a conjunction of literals is called a product.

◆ A Clause is a disjunction of literals, i.e. it is a sum.

◆ In the resolution rule: ((p q) (¬p r)) → (q r),

(q r) is called the resolvent.

◆ For any two clauses C1 and C2, if there is a literal L1

in C1 which is complementary to a literal L2 in C2 then delete L1 and L2 from C1 and C2 respectively, we have

a resolvent.

2019/9/10 CSE, NCHU

39

Resolution Principle◆ Definition: Given two clauses C1 and C2, a

resolvent C is a logical consequence of C1 and C2.

◆ The resolution principle Given a set S of clauses, a

resolution deduction of C from S is a finite sequence

C1, C2 ,.., Ck of clauses such that Ci is either a clause in S or a resolvent of clauses preceding C and CK= C. A deduction of empty clause is called a refutation or a (an inconsistent) proof of S.

◆ Consequently, for premises P1,…, Pn, and conclusion C, if put P1,…, Pn in clauses form and add it to ¬C,

then we should get an empty clause. 2019/9/10 CSE, NCHU

40

Examples of Resolutions◆ Show the following argument is correct.

If today is Tuesday, I have a test in Math. or Economics. If my Economics Professor is sick, I will not have a test in Economics. Today is Tuesday and Economics Professor is sick. Therefore, I have a test in Math.

◆ Proof Let T denote ‘today is Tuesday’

M denote ‘I have a test in Math.’

E denote ‘I have a test in Economics’

S denote ‘My Economics Prof. is sick’

we have T → (M E), S → ¬E, consequently, M should be true.

(Watch out: incomplete1 inference, the case works in the situation of both “today is Tuesday” and “E. Prof. is sick” are true.)

2019/9/10 CSE, NCHU

41

Fallacy of Affirming the Conclusion

◆ If you do every problem in this book, then you will learn discrete mathematics.

You learned discrete, therefor you did every problem in this book.

A: Let p be “you did every problem in this book”

q be “you learned discrete mathematics”

If p → q, and q, then p

which is false.

2019/9/10 CSE, NCHU

42

Fallacy of Denying the Hypothesis

◆ If you do every problem in this book, then you will learn discrete mathematics.

You do every problem in this book.

You did not learn discrete mathematics if you did not do every problem in this book.

A: If p → q, and ¬p, then ¬q

which is false.

2019/9/10 CSE, NCHU

43

Universal Modus Tollens◆ (x (P(x) → Q(x)) ¬Q(a)) → ¬P(a)Q: Which rules are used in the following argument?

No man is an island. Manhattan is an island. Therefore, Manhattan is not a man.

◆ Let M (x) be “x is a man”, I(x) be “x is an island”. Domain of x is “all things”. The premises are:

x (M(x) → ¬I(x))

I(Manhattan) (Note that Manhattan is an instance)

Therefore, by universal modus tollens, we can conclude that ¬M(Manhattan).

2019/9/10 CSE, NCHU

44

Universal Modus Ponens◆ (x (P(x) → Q(x)) P(a)) → Q(a)

◆ Assume that “For all positive integers n, if n is greater than 4, then n2 is less than 2n”

Want to prove 1002 < 2100

◆ Let P(n) denote “n > 4”

Q(n) denote “n2 < 2n”

Assume that x (P(n) → Q(n)) is true,

Note that P(100) is true, by universal modus

ponens, we have proved 1002 < 2100

2019/9/10 CSE, NCHU

45

Remarks on and ◆ Verify whether the followings are true or not :

(i) x (P(x) Q(x)) ≡ x P(x) x Q(x) D={2,3}

(ii) x (P(x) Q(x)) ≡ x P(x) x Q(x) (T)

(iii) x (P(x) Q(x)) ≡ x P(x) x Q(x) (T)

(iv) x (P(x) Q(x)) ≡ x P(x) x Q(x) D={1,2,3,5}

Think about the domain is {all prime numbers} or integers.

P(x) denotes “x is a multiple of 2” or Even numbers

Q(x) denotes “x is a multiple of 3” or Odd numbers

2019/9/10 CSE, NCHU

46

First-Order Logic

For a fixed vocabulary Γ, each formula of first-order logic (FO) is a string of symbols taken from the alphabet consisting of:

1. v1, v2, … variables

2. ¬ and for not and or

3. existential quantifier

4. =, (,), equality and parentheses

And, all symbols are in Γ.

2019/9/10 CSE, NCHU

47

MEMO

◼ Read section 1.4, 1.5, and 1.6

◼ Why from propositions, predicates, to rules of inference? For what?

◼ Get familiar with Modus ponens, Modus tollens, and Resolution.

◼ Practice translating English sentences to predicate logic statements by applying rules of inference

◼ HW #6,7,9,15,17,18,21-27,31 of §1.4, #9-11,15-17,21,23,24 of §1.5, #9,13-16 of §1.6

2019/9/10 CSE, NCHU