mathematical structures for computer science chapter 1.2 copyright © 2006 w.h. freeman &...

24
Formal Logic Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co. MSCS Slides Formal Logic

Upload: victor-wheeler

Post on 01-Jan-2016

226 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Formal Logic

Mathematical Structures for

Computer ScienceChapter 1.2

Copyright © 2006 W.H. Freeman & Co. MSCS SlidesFormal Logic

Page 2: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 2

Propositions or statements are sentences that are either true or false.

In logic, propositions are represented by the letters A, B, C, …

Propositions can be combined into more complicated expressions known as well-formed formulas, or wffs.◦ The connectives: and (), or (), implies (), and

negation () Wffs are represented by the letters P, Q, R,

Section 1.2

Review

Page 3: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 3

o A system for determining whether or not a particular logical argument is valid, using rules of inference (also known as propositional calculus.)

o Definition of Argument:o A sequence of statements in which the conjunction of the initial

statements (called the premises, or hypotheses) is said to imply the final statement (called the conclusion).

o Presented symbolically as (P1 Λ P2 Λ ... Λ Pn) Q

where P1, P2, ..., Pn represent the hypotheses and Q represents the conclusion.

Section 1.2

Propositional Logic

Page 4: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 4

What is a valid argument? When does Q logically follow from P1, P2, ..., Pn?

Informal answer: When the truth of the hypotheses guarantees the truth of the conclusion.

Note: We need to be sure the hypotheses are related to the conclusion; not just any knowledge we might have about the conclusion Q.

Example:◦ P1: Neil Armstrong was the first human to step on the moon.

◦ P2 : Mars is a red planet

And the conclusion◦ Q: No human has ever been to Mars.◦ P1, P2 , and Q are all true, but Q isn’t a logical consequence

Section 1.2

Valid Argument

Page 5: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 5

Definition of valid argument:

In a formal logical system an argument is valid if, whenever the hypotheses are all true, the conclusion must also be true. i.e. (P1 Λ P2 Λ ... Λ Pn) Q is a tautology. ◦ You must be able to logically deduce Q from the hypotheses

How to arrive at a valid argument?◦ Using a proof sequence

Section 1.2

Valid Argument

Page 6: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 6

Definition of Proof Sequence:

A proof sequence is a sequence of wffs in which each wff is either a hypothesis or the result of applying one of the formal system’s derivation rules to earlier wffs in the sequence.

Derivation rules allow you to rewrite a hypothesis in a more useful form, based on the equivalence relations from section one, or to derive new wffs from the old ones.

Section 1.2

Valid Argument

Page 7: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 7

Derivation rules for propositional logic

Section 1.2

Rules for Propositional Logic

Equivalence Rules Inference Rules

Allows individual wffs to be rewritten

Allows new wffs to be derived

Truth preserving rules

Work only in one direction

Page 8: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 8

Certain pairs of wffs are equivalent, hence one can be substituted for the other with no change to truth values.

The set of equivalence rules are summarized here:Let R and S be statement variables

Section 1.2

Equivalence Rules

Expression Equivalent to Abbreviation for rule

P V QP Λ Q

Q V PQ Λ P

Commutative(comm)

(P V Q) V R (P Λ Q) Λ R

P V (Q V R)P Λ (Q Λ R)

Associative(assoc)

(P V Q) (P Λ Q)

P Λ QP V Q

De Morgan’s Laws

P Q P V Q Implication (imp)

P (P) Double Negation (dn)

PQ (P Q) Λ (Q P)

Equivalence (equ)

Page 9: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 9

Inference rules allow us to add a new wffs to aproof sequence. If one or more wffs match an existing part of the proof sequence (this is the “from” part) you can deduce the second part and add to the proof.

Note: Inference rules do not work in both directions, unlike equivalence rules.◦ E.g., if you know R V S you can’t deduce R (or S).

Section 1.2

Inference Rules

From Can Derive Abbreviation for rule

R, R S S Modus Ponens- mp

R S, S R Modus Tollens- mt

R, S R Λ S Conjunction-con

R Λ S R, S Simplification- sim

R R V S Addition- add

Page 10: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 10

Example for using Equivalence rule in a proof sequence:◦ Simplify (A V B) V C

1. (A V B) V C2. (A Λ B) V C 1, De Morgan3. (A Λ B) C 2, imp

Example of using Inference Rule◦ If it is bright and sunny today, then I will wear my sunglasses.

Modus Ponens (given P, P S, conclude S) It is bright and sunny today. Therefore, I will wear my sunglasses. Modus Tollens (given P S, S, conclude P)I will not wear my sunglasses. Therefore, it is not bright and sunny today.

Section 1.2

Examples

Page 11: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 11

Prove the argumentA Λ (B C) Λ [(A Λ B) (D V C)] Λ B D

◦ First, write down all the hypotheses.1. A2. B C3. (A Λ B) (D V C)4. BUse the inference and equivalence rules to get at the conclusion D.5. C 2,4, mp6. A Λ B 1,4, con7. D V C 3,6, mp8. C V D 7, comm9. C D 8, imp

and finally10. D 5,9 impThe idea is to keep focused on the result and sometimes it is very easy

to go down a longer path than necessary.

Section 1.2

Proofs using Propositional Logic

Page 12: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 12

Used to prove an argument of the form P1 Λ P2 Λ ... Λ Pn R Q

Deduction method allows for the use of R as an additional hypothesis and thus prove

P1 Λ P2 Λ ... Λ Pn Λ R Q

Suppose you want to prove [(A B) Λ (B C)] (A C)

Section 1.2

Deduction Method

Page 13: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 13

Prove [(A B) Λ (B C)] (A C)Using deduction method, prove (A B) Λ (B C) Λ A C1. A B hyp2. B C hyp3. A hyp4. B 1,3 mp5. C 2,4 mp

The above is called the rule of Hypothetical Syllogism or hs for short.

Many such other rules can be derived from existing rules which thus provide easier and faster proofs.

Section 1.2

Deduction Method

Page 14: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 14

These rules can be derived using the previous rules. They provide a faster way of proving arguments.

Section 1.2

More Inference Rules

From Can Derive Name / Abbreviation

P Q, Q R P R Hypothetical syllogism- hs

P V Q, P Q Disjunctive syllogism- ds

P Q Q P Contraposition- cont

Q P P Q Contraposition- cont

Page 15: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 15

Additional inference rules yield shorter proofs, but more rules to remember.

Section 1.2

More Inference Rules

From Can Derive Name / Abbreviation

P P Λ P Self-reference – self

P V P P Self-reference – self

(P Λ Q) R P (Q R) Exportation – exp

P, P Q Inconsistency – inc

P Λ (Q V R) (P Λ Q) V (P Λ R)

Distributive - dist

P V (Q Λ R) (P V Q) Λ (P V R)

Distributive - dist

Page 16: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 16

Prove that (P Q) (Q P) is a valid argument (called Contraposition – con).◦ Hence prove, (P Q) Λ Q P (using deduction method).◦ The above is true using the modus tollens inference rule.

Prove P Λ P Q (called Inconsistency)1. P hyp2. P hyp3. P V Q 1, add4. Q V P 3, comm5. (Q) V P 4, dn6. Q P 5, imp: (A V B) (A B)

7. (Q) 2, 6, mt: from (P S, S ) get P8. Q 7, dn

Section 1.2

Proofs of inference rules

Page 17: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 17

(A Λ B) Λ (C Λ A) Λ (C Λ B) A is an argument

1. (A Λ B) hyp2. (C Λ A) hyp3. (C Λ B) hyp4. A V B 1, De Morgan5. B V A 4, comm6. B A 5, imp7. (C) V A 2, De Morgan8. C A 7, imp9. C V (B) 3, De Morgan10. (B) V C 9, comm11. B C 10, imp12. B A 8, 11, hs13. (B A) Λ (B A) 6, 12, con

Section 1.2

More Proofs

Page 18: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 18

At this point, we have now to prove that

(B A) Λ (B A) A

Proof sequence

1. B A hyp2. B A hyp3. A B 1, cont4. A A 3, 2, hs5. A V A 4, imp6. A 6, self

Section 1.2

Proof Continued

Page 19: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 19

To convert a verbal argument to a symbolic form so it can be tested for validity:

“Symbolize” the argument using propositional wff’s Use the derivation rules for propositional logic to prove the

argument is valid Example:

“If interest rates drop, the housing market will improve. Either the federal discount rate will drop or the housing market will not improve. Interest rates will drop. Therefore the federal discount rate will drop.”

LetI represent Interest rates dropH represent The housing market will improveF represent The federal discount rate will dropThen

(I H) (F H) I F

Section 1.2

Proving Verbal Arguments

Page 20: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 20

A proof sequence for (I H) (F H) I F

1. I H hyp2. F H hyp3. I hyp4. H F 2, comm5. H F 4, imp6. I F 1, 5, hs7. F 5, 3, mp

Section 1.2

Proving Verbal Arguments

Page 21: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 21

Russia was a superior power, and either France was not strong or Napoleon made an error. Napoleon did not make an error, but if the army did not fail, then France was strong. Hence the army failed and Russia was a superior power.

Converting it to a propositional form using letters A, B, C and DA: Russia was a superior powerB: France was strong B: France was not strongC: Napoleon made an error C: Napoleon did not make an errorD: The army failed D: The army did not fail

Combining, the statements using logic(A Λ (B V C)) hypothesisC hypothesis(D B) hypothesis(D Λ A) conclusion

Combining them, the propositional form is (A Λ (B V C)) Λ C Λ (D B) (D Λ A)

Section 1.2

Proving Verbal Arguments

Page 22: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 22

Prove (A Λ (B V C)) Λ C Λ (D B) (D Λ A)

Proof sequence1. A Λ (B V C) hyp2. C hyp3. D B hyp4. A 1, sim5. B V C 1, sim6. C V B 5, comm7. B 2, 6, ds8. B (D) 3, cont9. (D) 7, 8, mp10. D 9, dn11. D Λ A 4, 10 , con

Section 1.2

Verbal Argument Proof

Page 23: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 23

Prove the following arguments◦ (A´ B´) Λ (A C) (B C) ◦ (Y Z´) Λ (X´ Y) Λ [Y (X W)] Λ (Y Z) (Y W)

If the program is efficient, it executes quickly. Either the program is efficient, or it has a bug. However, the program does not execute quickly. Therefore it has a bug. (use letters E, Q, B)

The crop is good, but there is not enough water. If there is a lot of rain or not a lot of sun, then there is enough water. Therefore the crop is good and there is a lot of sun. (use letters C, W, R, S)

Section 1.2

Class Exercise

Page 24: Mathematical Structures for Computer Science Chapter 1.2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic

Propositional Logic 24

Write down the propositional form of the following argument:

If my client is guilty, then the knife was in the drawer. Either the knife was not in the drawer or Jason Pritchard saw the knife. If the knife was not there on October 10, it follows that Jason Pritchard didn’t see the knife. Furthermore, if the knife was there on October 10, then the knife was in the drawer and also the hammer was in the barn. But we all know that the hammer was not in the barn. Therefore, ladies and gentlemen of the jury, my client is innocent.

Section 1.2

Class Exercise