42
ประพจน์ (Propositions) ประโยคที่สามารถกาหนดค่าความจริง (Truth Values) ได้ ในตรรกคณิตศาสตร์จะเรียกประโยค ประเภทนี้ว่า ข้อความ (statement)” หรืออาจจะ เรียกว่า ประพจน์ (Proposition)ประโยคที่ไม่มีค่าความจริงจะไม่เป็นประพจน์ เช่นประโยค คาถาม ประโยคขอร้อง ประโยคคาสั่ง

ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Embed Size (px)

Citation preview

Page 1: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

ประพจน (Propositions) • ประโยคทสามารถก าหนดคาความจรง (Truth

Values) ได ในตรรกคณตศาสตรจะเรยกประโยคประเภทนวา “ขอความ (statement)” หรออาจจะเรยกวา “ประพจน(Proposition)”

• ประโยคทไมมคาความจรงจะไมเปนประพจน เชนประโยคค าถาม ประโยคขอรอง ประโยคค าสง

Page 2: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Propositional Logic • Propositional Logic เปนตรรกของขอความหลายๆ ขอความทเกยวเนองกน (compound statements) โดยจะเรยกตรรกนวา Boolean connectives.

นยาม: ประพจนใดๆ (มกจะแทนดวย p, q, r, …) กคอ:

• ขอความ (สวนใหญแลวจะอยในรปของประโยค) ทมความหมายบางอยางและความหมายจะตองมความชดเจน

• และประพจนจะตองมคาความจรง (Truth value) โดยคาความจรงนจะมคาเปนจรง (true: T) หรอไมกเทจ (false: F)

George Boole

(1815-1864)

Page 3: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Truth table • The connective | is called the Sheffer stroke. The

connective ↓ is called the Peirce arrow. • The values of the compound propositions obtained by

using the binary connectives are given in the following table:

In the conditional p → q, p is the antecedent and q is the consequent. The conditional p → q is often read informally as “p implies q”.

Page 4: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

ตวด ำเนนกำรบลนโดยทวไป

Formal Name Nickname Arity Symbol

Negation operator NOT Unary ¬,~

Conjunction operator AND Binary

Disjunction operator OR Binary

Exclusive-OR operator XOR Binary

Implication operator IMPLIES Binary

Biconditional operator IFF Binary ↔

Page 5: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Examples:

1. “x > 5” is not a proposition,

because its truth value cannot be determined unless the value of x is known.

2. ใหแสดงล าดบการท างานของสเตจเมนตตอไปนดวยวงเลบ

Page 6: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

1.1.2 EQUIVALENCES, IDENTITIES, AND NORMAL FORMS • Tautology เปนประพจนเชงประกอบทเปนจรงเสมอ

• contradiction (or self-contradiction) เปนประพจนเชงประกอบทเปนเทจเสมอ

• A compound proposition P logically implies a compound proposition Q, written P -> Q, if Q is true whenever P is true. In this case, P is stronger than Q, and Q is weaker

than P.

• Compound propositions P and Q are logically equivalent, written P ≡ Q, P ⇔ Q, or P iff Q, if they have the same truth

values for all possible truth values of their variables.

• A logical equivalence that is frequently used is sometimes called a logical identity.

Page 7: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective
Page 8: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Proof by truth table

Proof by series of logical equivalences:

Page 9: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Predicate Logic • Predicate logic is an extension of

propositional logic that permits concisely reasoning about whole classes of entities.

• Propositional logic (recall) treats simple propositions (sentences) as atomic entities.

• In contrast, predicate logic distinguishes the subject of a sentence from its predicate.

– Remember these English grammar terms?

Page 10: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Subjects and Predicates • In the sentence “The dog is sleeping”:

– The phrase “the dog” denotes the subject - the object or entity that the sentence is about.

– The phrase “is sleeping” denotes the predicate- a property that is true of the subject.

• In predicate logic, a predicate is modeled as a function P(·) from objects to propositions. – P(x) = “x is sleeping” (where x is any object).

Page 11: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Universes of Discourse (U.D.s)

• The power of distinguishing objects from predicates is that it lets you state things about many objects at once.

E.g., let P(x)=“x+1>x”. We can then say,

“For any number x, P(x) is true” instead of (0+1>0) (1+1>1) (2+1>2) ...

• The collection of values that a variable x can take is called x’s universe of discourse.

Page 12: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Quantifier Expressions • Quantifiers provide a notation that allows

us to quantify (count) how many objects in the univ. of disc. satisfy a given predicate.

• “” is the FORLL or universal quantifier. x P(x) means for all x in the u.d., P holds.

• “” is the XISTS or existential quantifier. x P(x) means there exists an x in the u.d. (that is, 1 or more) such that P(x) is true.

Page 13: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Free and Bound Variables

• An expression like P(x) is said to have a free variable x (meaning, x is undefined).

• A quantifier (either or ) operates on an expression having one or more free variables, and binds one or more of those variables, to produce an expression having one or more bound variables.

Page 14: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Example of Binding P(x,y) has 2 free variables, x and y.

x P(x,y) has 1 free variable, and one bound variable. [Which is which?]

“P(x), where x=3” is another way to bind x.

An expression with zero free variables is a actual proposition.

An expression with one or more free variables is still only a predicate: e.g. let Q(y) = x P(x,y)

Page 15: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective
Page 16: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

กฎกำรอนมำนในรปแบบทวไป

นยาม กฎการอนมานเปนการสรางรปแบบ เมอเรารวาเซตของขอความทเปนเหต (Antecedent) มรปแบบทแนนอนเปนจรงทงหมด ดงนนเราจะเชอไดวาสวนของผลทสมพนธอยกบเหต (Consequent) เปนจรง

สจนรนดร (Tautology) (p(pq))q เปนพนฐานของกฎการอนมานทเรยกวา โมดสโพเนน (Modus ponens) ทเขยนอยในรป

p

pq q เพราะฉะนน

antecedent 1 antecedent 2

… antecedent n

consequent

Page 17: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Modus Ponens

• Consider (p (p→q)) → q

p

p q

q

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

T T T T T

T F F F T

F T T F T

F F T F T

Page 18: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

ตวอยำง Modus ponens

• ตวอยางท 1 ประพจนแบบมเงอนไข “ถาฝนตกวนนท าใหรถตด”

สมมตฐาน p คอ “ถาฝนตกวนน” เปนจรง ดงนนโดย modus ponens กจะสรป q วา “รถตด” กจะเปนจรง นนคอ

(p(pq))q

สมมตฐาน p: วนนฝนตก if p then q

q is True

Conclusion: q is True

Page 19: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Modus Tollens

• Assume that we know: ¬q and p → q

– Recall that p → q ¬q → ¬p

• Thus, we know ¬q and ¬q → ¬p

• We can conclude ¬p

q

p q

p

Page 20: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Modus Tollens example

• สมมตวาเหตการณทเกดขนเปนไปตามประพจนตอไปน:

– “คณไมไดเกรดวชาน”

– “ถาคณลงทะเบยนเรยนวชานกจะไดเกรดใดเกรดหนง”

• ก าหนดให p = “คณลงทะเบยนเรยนวชาน”

• ก าหนดให q = “คณจะไดเกรด”

• ตามการใหเหตผลแบบ Modus Tollens, กสามารถสรปไดวาคณไดไดลงทะเบยนเรยนวชาน

q

p q

p

Page 21: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Modus Ponens & Tollens

p Rule of modus ponens pq (a.k.a. law of detachment) q (p ( p q)) q

q pq Rule of modus tollens p (q (p q)) p

“the mode of affirming”

“the mode of denying”

p Rule of modus ponens pq (a.k.a. law of detachment) q (p ( p q)) q

q pq Rule of modus tollens p (q (p q)) p

“the mode of denying”

Page 22: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

ตำรำงกฎกำรอนมำน

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

Page 23: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective
Page 24: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective
Page 25: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective
Page 26: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

ตวอยางการพสจน

• สมมตฐานทจะพสจนคอ: – “ลนดาเปนนกศกษาในหองน, ลนดามความขยน”

– “ทกคณทมความขยนกจะสอบไดระดบคะแนนทด”

• สามารถสรปไดหรอไมวา: “บางคนทในชนเรยนนสอบไดระดบคะแนนด”?

C(Linda)

R(Linda)

x (R(x)→T(x))

x (C(x)T(x))

Page 27: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Example of proof

1. x (R(x)→T(x)) 3rd hypothesis

2. R(Linda) → T(Linda) Universal instantiation using step 1

3. R(Linda) 2nd hypothesis

4. T(Linda) Modes ponens using steps 2 & 3

5. C(Linda) 1st hypothesis

6. C(Linda) T(Linda) Conjunction using steps 4 & 5

7. x (C(x)T(x)) Existential generalization using step 6

จากการพสจนไดแสดงใหเหนวา “บางคนทในชนเรยนนสอบไดระดบคะแนนด”

Page 28: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective
Page 29: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective
Page 30: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective
Page 31: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

1.6 AXIOMATIC PROGRAM VERIFICATION

Axiomatic program verification is used to prove that a sequence of programming instructions achieves its specified objective.

• Semantic axioms for the programming language constructs are used in a formal logic argument as rules of inference.

1.6.1 ASSERTIONS AND SEMANTIC AXIOMS

• The correctness of a program can be argued formally based on a set of semantic axioms that define the behavior of individual programming language constructs.

Page 32: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Definitions: • An assertion is a program comment containing a logical statement that constrains

the values of the computational variables. These constraints are expected to hold when execution flow reaches the location of the assertion.

• A semantic axiom for a type of programming instruction is a rule of inference that prescribes the change of value of the variables of computation caused by the execution of that type of instruction.

• The assertion false represents an inconsistent set of logical conditions. A computer program cannot meet such a specification.

• Given two constraints A and B on computational variables, a statement that B follows from A purely for reasons of logic and/or mathematics is called a logical implication.

• The postcondition for an instruction or program fragment is the assertion that immediately follows it in the program.

• The precondition for an instruction or program fragment is the assertion that immediately precedes it in the program.

• The assertion true represents the empty set of logical conditions.

Page 33: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Notation: • To say that whenever the precondition {Apre} holds, the execution

of a program fragment called “Code” will cause the postcondition {Apost} to hold, the following notation styles can be used:

Semantic axioms A->B

Page 34: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

1.6.2 NOP, ASSIGNMENT, AND SEQUENCING AXIOMS

• Formal axioms of pure mathematical consequence (no operation, from a computational perspective) and of straight-line sequential flow are used as auxiliaries to verify correctness, even of sequences of simple assignment statements. – assignment instruction X := E; – logical assertion A(X)

Page 35: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective
Page 36: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

1.6.3 AXIOMS FOR CONDITIONAL EXECUTION CONSTRUCTS

• A conditional assignment construct is any type of program instruction containing a logical condition and an imperative clause such that the imperative clause is to be executed if and only if the logical condition is true.

Page 37: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

An if-then-else instruction

Page 38: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective
Page 39: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

1.6.4 AXIOMS FOR LOOP CONSTRUCTS

Page 40: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective
Page 41: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

1.6.5 AXIOMS FOR SUBPROGRAM CONSTRUCTS

Definitions: • A procedure is a sequence of instructions that lies

outside the main sequence of instructions in a program. It consists of a procedure name, followed by a procedure body.

• A call instruction call ProcName is executed by transferring control to the first executable instruction of the procedure ProcName.

• A return instruction causes a procedure to transfer control to the executable instruction immediately following the most recently executed call to that procedure. An implicit return is executed after the last instruction in the procedure body is executed. It is good programming style to put a return there.

Page 42: ประพจน์ (Propositions) - เว็บไซต์บุคลากร ...staff.cs.psu.ac.th/sathit/344-281/Recovery.pdf ·  · 2014-06-17Truth table •The connective

Axiom of Procedure (parameterless),