Download presentation
Presentation is loading. Please wait.
Published byPhilomena Lyons Modified over 9 years ago
1
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Logic
2
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Symbols & Reasoning –Each “structure” is represented as symbol Possible since the “structures” are discrete –Formal Logic: The study of systems of deductive argument in which symbols are used to represent precisely defined categories of expressions Formal logic deals with the manipulation of truth values (i.e., arguments). –Given one truth we wish to find another truth
3
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Connectives –Truth Tables Conjunction ( ) Disjunction ( ) Implication ( ) Equivalence ( ) Negation (¬) –Order of Precedence (in our text): ( ) ¬ , Well-formed formula (WFF): A formula constructed in accordance with the syntactic rules of logical connectives. AB ABABBABA(A B) (B A) TTTTT TFFTF FTTFF FFTTT Propositional Logic: The logic of propositions (atomic statements).
4
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Truth Tables Applied –Full Adder –Gate Representation (Sum of Products): CinABCout FFFF FFTF FTFF FTTT TFFF TFTT TTFT TTTT Cin A B handles both “OR” Gate “AND” Gate
5
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Special WFFs –Tautology A WFF that is always true “intrinsically true” Example: A ¬A –Contradiction A WFF that is always false “intrinsically false” Example: A ¬A Both are important in matters of argument (i.e., proof). The text shows several tautologies and equivalences of particular importance (p. 8 & 23)
6
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Argument & Implication (1) –An argument has the form Given x and y we can conclude z What does this mean in logic? When should this be considered a valid argument? Hypothesis: When x y z is true –Recall: A B is true if A is false! –Valid Argument An argument P Q is valid if it is a tautology. Example: ((A B) A) B Fallacy: an incorrect or misleading notion or opinion based on inaccurate facts or invalid reasoning “modus ponens” AB A B(A B) A((A B) A) B TTTTT TFFFT FTTFT FFTFT
7
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 Rules of Inference (a) Modus ponens (Latin: mode that affirms ) is a valid, simple argument form 1.If p, then q (p q) is true 2. p p is true or (p q)^p are truethen q is true 3. q (b) Modus tollens (Latin: mode that denies ) is the formal name for indirect proof or proof by contrapositve 1. If p, then q 2. -q (p q)^~q ~p 3. -p
8
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 Rules of Inference Exercise 1. If I go to Mars,, I will run for office., I am going to Mars. Therefore, I will run for office 2. If I go to Mars,, I will run for office., I am going to run for office. Neither rules apply. 3. If I go to Mars,, I will run for office., I am not going to Mars. Neither rules apply.
9
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 Rules of Inference II. Two Deductively Invalid Rules of Inference (a) Affirming the Consequent 1. If p, then q 2. q 3. p (b) Denying the Antecedent 1. If p, then q 2. -p 3. -q
10
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Rules of Inference (complete) If P is true, and P Q is true then Q is true, can be written as: 1.P, P Qthen Q (Modus Ponens, MP) 2.¬Q, P Qthen ¬P(Modus Tollens MT) 3.P, Qthen P Q (Conjunction) 4.P QthenP, Q(Simplification) 5.Pthen P Q (Disjunction or Add) They do not work in both directions, i.e., take rule 1: Q then P, P Q is false Only works for equivalence rules (next slide)
11
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Equivalence Rules 1.Commutative law: P Q is equiv. to Q P P Q ≡ Q P 2.Associative law: (P Q) R ≡ P (Q R) (P Q) R ≡ P (Q R) 3.De Morgan’s Law: ¬ (P Q) ≡ ¬ P ¬Q ¬ (P Q) ≡ ¬ P ¬Q
12
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Equivalence Rules 4.Implication Law: P Q ≡ ¬P Q 5.Double Negation Law: P ≡ ¬ (¬P ) 6.Definition of equivalence: P Q ≡ (P Q) (Q P)
13
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. To prove an argument: –Do we need to generate the truth table to test if it is a tautology? No. –Use truth-maintaining derivations Turn an existing wff into an equivalent wff –Called equivalence rules –Works in both directions –Page 23 of text Add a new wff based on existence of other wffs –Called inference rules –Does not work in “reverse” –Pages 24 and 31 of text “inference” – the act of concluding (a state of affairs, supposition, etc.) by reasoning from evidence
14
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Characteristics of a Proof Sequence –Given P 1 P 2 …….P n Q –Use formal logic to prove that Q is a valid conclusion from P 1,….P n, with the following proof sequence: P 1 (hypothesis) P 2 (hypothesis) : P n (hypothesis) wff 1 (derived from earlier wffs – see next slide) : wff m (derived from earlier wffs) Q(derived from earlier wffs)
15
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Argument & Implication (3) –Sample proof sequence ¬A (B A) ¬B is a valid argument 1.¬AHypothesis 2. (B A) Hypothesis 3. ¬B A 2,imp 4.¬B1,3,resolution Implication Rule: P Q is the same as ¬P Q
16
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. More Examples Prove that the following argument is valid: A (B C) [(A B) (D ¬C) ] B D 1.determine which term is the conclusion. 2.Separate each term to the left of as a hypothesis. A (B C) [(A B) (D ¬C) ] B D 1.There are four hypotheses (separated by ) (a) A (b) (B C) (c) ((A B) (D ¬C) (d) B
17
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Examples (cont’d) Look at the obvious (stated) hypothesis and try to apply inference rules to get more truths: (1) Ahyp (2) (B C) hyp (3) ((A B) (D ¬C) hyp (4) Bhyp New truths are: (5) C4,2, MP (from 4, B is true; apply mp to 2 to get C (6) (A B) 1,4, conjuction (7) (D ¬C) 3,6, mp Apply this to (3) to get (D ¬C) What is the objective? To derive all variables in arguments to reach conclusion; we have D left that needs to be resolved.
18
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Examples (cont’d) We need to resolve D, so far, we have: (1) Ahyp (2) (B C) hyp (3) ((A B) (D ¬C) hyp (4) Bhyp (5) C4,2, MP (6) (A B) 1,4, conjuction (7) (D ¬C) 3,6, mp From (7), note that D ¬C is true. In other words, ¬C D is true, hence by applying deMorgan’s Law, (8) ¬C D 7, commutative (9) C D7, imp (10) D8, mp
19
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Law of Hypothetical Syllogism (hs) –A.k.a. Transitive Law of Implication Given A B and B C then A C This can be done in two ways: 1.Using transitivity 2.Proving new rule as part of the proof.
20
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Law of Hypothetical Syllogism Example (¬A B) (B C) (A C) truetrueconclusion Method 1 1. ¬A Bhyp 2.B C hyp 3.A B1, imp 4.A C 3,2, hs Method 2 1. ¬A Bhyp 2. B C hyp 3 A B1, imp 4. Ahyp 5 B4, 3, mp 6 C5, 2, mp
21
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Expert Systems (2) –Example: Medical Diagnosis Knowledge exists on the relationships between symptoms and deceases Encode that knowledge in logical implications S2 S3 I1 S1 I1 D1 S4 S5 I2 I1 ¬I2 D2 Encode the current symptoms S1 S2 ¬ S3 ¬ S4 ¬ S5 Use derivation to determine which diseases are true 1. S1 s2 ¬s3… Hypothesis 2.S21,sim 3. S2 s3 2,add 4.I13,imp 5.S11,sim 6. S1 I1 4,5,con 7.D16,imp
22
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Predicate Logic (1) –Propositional logic is quite limiting Only speaks in terms of atomic objects No properties to the objects No relationships to other objects –Clearly not realistic –Predicate logic uses explicit predicates for representing properties of objects and relations between objects –Predicate logic also adds the concept of variables and quantification
23
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Predicate Logic (2) Example: All men are mortal. Properties: man, mortal Rewording: Everyone who has the property of being a man also has the property of being a mortal.” Predicate Logic x ( man(x) mortal(x) ) Note: x and almost always belong together. Compare to: x ( man(x) mortal(x) ) What does this translation mean? Example: Some days are not rainy Relations: day, rainy Predicate Logic x ( day(x) rain(x) )
24
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Predicate Logic (cont’d) Example: Some days are not rainy Relations: day, rainy Predicate Logic x ( day(x) rain(x) )
25
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Predicate Logic (3) –Example: Everybody loves somebody Relations: loves, person Translations: x y ( person(x) person(y) loves(x,y) ) x ( person(x) y (person(y) loves(x,y) ) ) x y loves(x,y) Assumes only people are involved Allows the inference of the existence of second person from the existence of a single person Requires two people to exist before any “love” can happen.
26
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Predicate Logic (4) Charity(x), Money(x), Person(x), BelongsTo(x,y), Donates(x,y,z) Somebody donates all his/her money to charity. “There exists at least one person such that for each unit of money that belongs to that person there exists a charity to which that person donated that money.” x [person(x) y[money(y) belongs(y,x) z[charity(z) donates(x,y,z)]]] Some donors donate to every charity. “At least one donor donates some thing or another to every charity.” x[ y[charity(y) z[donates(x,z,y)]]]
27
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Predicate Logic (4) Some charities receive donations from everybody. “There is at least one charity for which every person donates at least one thing.” x[charity(x) y[person(y) z[donates(y,z,x)]]] Some charities receive donations from every donor. “At least one charity is donated some thing from every person who donates some thing to some charity.” x[charity(x) y z w[(person(y) ^ charity(w) ^ donates(y,z,w)) v[donates(y,v,x)]]]
28
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Predicate Logic (5) –Interpretation Propositional was easy – each piece is either true or false Predicates add complexity An interpretation consists of: –A collection of objects, called the domain which must include at least one object –An assignment of a property of the objects in the domain to each predicate in the expression –An assignment of a particular object in the domain to each constant symbol in the expression An universally quantified expression is true if the interpretation is true for all objects in the domain. An existentially quantified expression is true if the interpretation is true for at least one set of objects in the domain. Note: Nesting of quantifiers defines scope Free variables are possible Means we have picked some unspecified value x in the domain
29
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Predicate Logic (6) –Valid Arguments in Predicate Logic (1) Potentially infinite domain means the truth table approach is impossible in general Unlike with propositional logic, it has been proven that no algorithm exists for deciding validity of a predicate logic argument How do we prove a predicate logic argument valid? –By using truth-maintaining transformations The equivalence rules and inference rules for propositional logic still apply –Example: x R(x) [ y R(y) z S(z)] z S(z) 1. x R(x) hyp 2. y R(y) z S(z) hyp 3. z S(z) 1,2,mp A validity is a predicate wff that is true for all possible interpretations (analogous to tautology)
30
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Predicate Logic (7) –Valid Arguments in Predicate Logic (2) Four additional derivational rules –Universal Instantiation (ui) –Existential Instantiation (ei) –Universal Generalization (ug) –Existential Generalization (eg) Basic proof technique –Strip off quantifiers –Manipulate wffs –Put quantifiers back in Example: x y P(x,y) y x P(x,y) p. 47 of textApply to top-level formula 1. x y P(x,y) hyp 2. y P(a,y) 1,ei 3.P(a,b)2,ei 4. x P(x,b) 3,eg 5. y x P(x,y) 4,eg Of course, there are restrictions
31
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Predicate Logic (8) –Valid Arguments in Predicate Logic (3) Fallacy Example: x y P(x,y) y x P(x,y) 1. x y P(x,y) hyp 2. y P(x,y) 1,ui 3.P(x,b)2,ei 4. x P(x,b) 3,ug 5. y x P(x,y) 4,eg P(x,b) was deduced by ei from a wff in which x is free – NOT ALLOWED Also not allowed to use ug if P(x) is deduced from any hypothesis in which x is free. See page 47 of text!
32
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Proof of Correctness (1) –How do we know if our programs are right? Why do we care? –“This isn’t medicine, no one is going to die” What do you mean by “right”? –Verification – “Am I building the program right?” –Validation – “Am I building the right program?” Proof of Correctness deals with Verification, not Validation –When is a program right (or correct)? If it produces the correct output for every possible input –Two parts: »Program terminates »Output is correct
33
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Proof of Correctness (2) –Definition: partially correct A program, P, is partially correct with respect to an initial assertion q and the final assertion r if whenever q is true for the input values of P, then r is true for the output values of P. –Notation: {q}P{r} called Hoare Triple Note: This has nothing to do with whether a statement P halts –In formal logic, this is equivalent to x q(x) r(x, P(x)) –To prove that a program is correct, we must assert the desired postcondition and prove that it is true within the assumption that the precondition is true and the program has been performed
34
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Proof of Correctness (3) –We must therefore know how each program structure transforms postconditions into preconditions In other words, we need rules of inference that allow us to move from a given postcondition and program to an implied precondition –Assignment Rule of Inference if {R i }x = e{R i+1 } then R i is R i+1 with e substituted for each x Example: {x = y + 2} x = x – 2; {x = y}
35
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Proof of Correctness (4) –Composition Rule of Inference If {Q}P 1 {R 1 } {R 1 }P 2 {R 2 } {R 2 }P 3 {R} Then {Q}P 1 ;P 2 ;P 3 {R} Example: {x = 3} y = 4; {x + y = 7} z = x + y; {z = 7} So, to prove the final post condition we must find a sequence of valid preconditions
36
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Proof of Correctness (5) –Conditional Rule of Inference (1) If {Q B}P 1 {R} {Q ¬ B}P 2 {R} Then {Q}if B then P1 else P2{R} Example: {x = 4} if x < 5 then y = x – 1 else y = 7 {y = 3} {x = 4 x < 5} y = x - 1; {y = 3} {x = 4 x 5} y = 7; {y = 3} Assuming T = F, we can prove anything Recall x q(x) b(x) r(x,P 2 (x)) Recall truth table for implication
37
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Proof of Correctness (6) –Conditional Rule of Inference (2) Example: T if x > y then y = x; {y x} –Loop Rule of Inference Left until after mathematical induction {x > y} y = x; {y x} Means truth – no additional constraints on x or y (x > y) (x y) Note: We don’t have to transform postcondition to some predefined precondition just transform postcondition to a precondition that is true
38
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Application: Proof of Correctness (7) –Proof of Correctness in Action Do people really use this technique for large programs? –Yes and No –They use this technique on small, critical sections –They use a testing framework motivated, in part, by this technique (JUnit)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.