Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Discrete Mathematics Lecture 2. Dr.Bassant Mohamed El-Bagoury [email protected] Module Logic (part 2 --- proof methods) 1 Outline 1. Mathematical Reasoning 2. Arguments Examples – Predicate Logic 3. Rules of Inference – Knowledge Engineering 4. Rules of Inference for Quantifiers 4. Methods for Theorem Proving 2 Mathematical Reasoning 3 Mathematical Reasoning We need mathematical reasoning to • determine whether a mathematical argument is correct or incorrect and • construct mathematical arguments. Mathematical reasoning is not only important for conducting proofs and program verification, but also for artificial intelligence systems (drawing inferences). 4 Arguments Example: Gary is either intelligent or a good actor. If Gary is intelligent, then he can count from 1 to 10. Gary can only count from 1 to 2. Therefore, Gary is a good actor. i: “Gary is intelligent.” a: “Gary is a good actor.” c: “Gary can count from 1 to 10.” 5 Arguments i: “Gary is intelligent.” a: “Gary is a good actor.” c: “Gary can count from 1 to 10.” Step 1: Step 2: Step 3: Step 4: Step 5: c ic i ai a Hypothesis Hypothesis Modus Tollens Steps 1 & 2 Hypothesis Disjunctive Syllogism Steps 3 & 4 Conclusion: a (“Gary is a good actor.”) 6 Arguments Another example: “If it rains today, then we will not have a barbeque today. If we do not have a barbeque today, then we will have a barbeque tomorrow. Therefore, if it rains today, then we will have a barbeque tomorrow.” This is a valid argument: If its hypotheses are true, then its conclusion is also true. 7 AI research × Software Engineering Requirements Specification Intelligent Behaviour Knowledge Level System Level Symbol Level Functional Specification System Implementation A small Expert System ( Inference System ) of rules for analysis of automotive problems. Rule 1: if the engine is getting gas, and the engine will turn over, then the problem is spark plugs. Rule 2: if the engine does not turn over, and the lights do not come on then the problem is battery or cables. Rule 3: if the engine does not turn over, and the lights do come on then the problem is the starter motor. Rule 4: if there is gas in the fuel tank, and there is gas in the carburetor then the engine is getting gas. Fig The Inference System at the start of a consultation in the car diagnostic example. Fig The Inference System after Rule 1 has fired. The and/or graph searched in the car diagnosis example, with the conclusion of Inference Rule 4 matching the first premise of Inference Rule 1. The following dialogue begins with the computer asking the user about the goals present in working memory. Gas in fuel tank? Yes Gas in carburetor? Yes Engine will turn over? Why It has been established that: 1. The engine is getting gas, 2. The engine will turn over, Then the problem is the spark plugs. How the engine is getting gas This follows from rule 4: if gas in fuel tank, and gas in carburetor then engine is getting gas. gas in fuel tank was given by the user gas in carburetor was given by the user Terminology An axiom is a basic assumption about mathematical structures that needs no proof. We can use a proof to demonstrate that a particular statement is true. A proof consists of a sequence of statements that form an argument. The steps that connect the statements in such a sequence are the rules of inference. Cases of incorrect reasoning are called fallacies. A theorem is a statement that can be shown to be true. 14 Terminology A lemma is a simple theorem used as an intermediate result in the proof of another theorem. A corollary is a proposition that follows directly from a theorem that has been proved. A conjecture is a statement whose truth value is unknown. Once it is proven, it becomes a theorem. 15 Arguments Just like a rule of inference, an argument consists of one or more hypotheses and a conclusion. We say that an argument is valid, if whenever all its hypotheses are true, its conclusion is also true. However, if any hypothesis is false, even a valid argument can lead to an incorrect conclusion. 16 Arguments Example: “If 101 is divisible by 3, then 1012 is divisible by 9. 101 is divisible by 3. Consequently, 1012 is divisible by 9.” Although the argument is valid, its conclusion is incorrect, because one of the hypotheses is false (“101 is divisible by 3.”). If in the above argument we replace 101 with 102, we could correctly conclude that 1022 is divisible by 9. 17 Theorems, proofs, and rules of inference When is a mathematical argument (or “proof”) correct? What techniques can we use to construct a mathematical argument? Theorem – statement that can be shown to be true. Axioms or postulates or premises – statements which are given and assumed to be true. Proof – sequence of statements, a valid Argument, to show that a theorem is true. Rules of Inference – rules used in a proof to draw conclusions from assertions known to be true. 18 Valid Arguments (reminder) Recall: An argument is a sequence of propositions. The final proposition is called the conclusion of the argument while the other propositions are called the premises or hypotheses of the argument. An Argument is valid whenever the truth of all its premises implies the truth of its conclusion. How to show that q logically follows from the hypotheses (p1 p2 …pn)? Show that (p1 p2 …pn) q is a tautology One can use the rules of inference to show the validity of an argument. Vacuous proof - if one of the premises is false then (p1 p2 …pn) q is vacuously True, since False implies anything. 19 Methods for Proving Theorems 20 Methods of Proof 1) Direct Proof 2) Proof by Contraposition 3) Proof by Contradiction 4) Proof of Equivalences 5) Proof by Cases 6) Existence Proofs 7) Counterexamples 21 1) Direct Proof Proof statement : pq by: Assume p From p derive q. 22 Direct proof --- Example 1 Here’s what you know: Mary is a Math major or a CS major. If Mary does not like discrete math, she is not a CS major. If Mary likes discrete math, she is smart. Let Mary is not a math major. M - Mary is a Math major Can you conclude Mary is smart? C – Mary is a CS major Informally, what’s the inference chain of reasoning? D – Mary likes discrete math S – Mary is smart MC D C D S C) (D S) (M)) S ((M C) (D M ? 23 In general, to prove p q, assume p and show that q follows. ((M C) (D C) (D S) (M)) S ? 24 See Table 1, p. 66, Rosen. Reminder: Propositional logic Rules of Inference or Method of Proof Rule of Inference Tautology (Deduction Theorem) Name P PQ P (P Q) Addition PQ P (P Q) P Simplification P Q PQ [(P) (Q)] (P Q) Conjunction P PQ Q [(P) (P Q)] P Modus Ponens Q PQ P [(Q) (P Q)] P Modus Tollens PQ QR P R [(PQ) (Q R)] (PR) Hypothetical Syllogism (“chaining”) PQ P Q [(P Q) (P)] Q Disjunctive syllogism PQ P R QR [(P Q) (P R)] (Q R) Resolution Subsumes MP Example 1 - direct proof 1. 2. 3. 4. 5. 6. 7. MC D C DS M C D S Given (premise) Given Given Given DS (disjunctive syllogism; 1,4) MT (modus tollens; 2,5) MP (modus ponens; 3,6) QED Mary is smart! QED or Q.E.D. --- quod erat demonstrandum 26 Direct Proof --- Example 2 Theorem: If n is odd integer, then n2 is odd. Looks plausible, but… How do we proceed? How do we prove this? Start with Definition: An integer is even if there exists an integer k such that n = 2k, and n is odd if there exists an integer k such that n = 2k+1. Properties: An integer is even or odd; and no integer is both even and odd. (aside: would require proof.) 27 Example 2: Direct Proof Theorem: (n) P(n) Q(n), where P(n) is “n is an odd integer” and Q(n) is “n2 is odd.” We will show P(n) Q(n) 28 Theorem: If n is odd integer, then n2 is odd. Proof: Let P --- “n is odd integer” Q --- “n2 is odd” we want to show that P Q • Assume P, i.e., n is odd. • By definition n = 2k + 1, where k is some integer. • Therefore n2 = (2k + 1)2 = 4k2 + 4k + 1 = 2 (2k2 + 2k ) + 1, which is by definition is an odd number (use k’ = (2k2 + 2k ) ). QED Proof strategy hint: Go back to definitions of concepts and start by trying direct proof. MORE EXPLAINATION 30 The Foundations: Logic and Proofs Chapter 1 31 Propositional Logic Proposition is a declarative statement that is either true of false •Baton Rouge is the capital of Louisiana •Toronto is the capital of Canada •1+1=2 •2+2=3 True False True False Statements which are not propositions: •What time is it? •x+1 = 2 32 p today is Thursday Negation: p today is not Thursday truth table p p T F F T 33 p today is Thursday q it is raining today Conjunction: p q today is Thursday and it is raining today truth table p q pq T T T T F F F T F F F F 34 p today is Thursday q today is Friday Disjunction: p q today is Thursday or today is Friday truth table p q pq T T T T F T F T T F F F 35 p today is Thursday q today is Friday Exclusive-or: one or the other but not both p q today is Thursday or today is Friday (but not both) truth table p q pq T T F T F T F T T F F F 36 (hypothesis) p Maria learns discrete math (conclusion) q Maria will find a good job Conditional statement: p q if Maria learns discrete math then she will find a good job if p then q p implies q q follows from p p only if q p is sufficient for q truth table p q pq T T T T F F F T T F F T 37 Conditional statement: pq equivalent Contrapositive: q Converse: Inverse: p (same truth table) q p p q equivalent 38 p you can take the flight q you buy a ticket Biconditional statement: p q you can take the flight if and only if you buy a ticket p if and only if q p iff q If p then q and conversely p is necessary and sufficient for q truth table p q pq T T T T F F F T F F F T 39 Compound propositions p q q p q p q p q p q T T F T T T T F T T F F F T F F F T F F T T F F Precedence of operators higher lower 40 Translating English into propositions p " you cannot ride the roller coaster if you are under 4 feet tall unless you are older than 16 years old" q you can ride the roller coaster r you are under 4 feet tall s you are older than 16 years old p r s q 41 Propositional Equivalences Compound proposition Tautology: always true Contradiction: always false tautology p p contradiction p p p p T F T F F T T F Contingency: not a tautology and not a contradiction 42 Rules of Inference If you have a current password, then you can log onto the network You have a current password p Therefore, you can log onto the network q Valid argument: if premises are true then conclusion is true pq Modus Ponens pq p q 43 Modus Ponens pq p q (( p q) p) q If p q and p then q 44 Rules of Inference Modus Ponens Modus Tollens pq pq p q q p Hypothetical Syllogism pq Disjunctive Syllogism pq qr p pr q 45 Rules of Inference Addition Simplification p pq Conjunction pq p Resolution q pq p r pq q r p 46 It is below freezing now Therefore, p it is either below freezing q or raining now p pq Addition p pq 47 p It is below freezing q and raining now Therefore, it is below freezing now pq p Simplification pq p 48 p q If it rains today then we will not have a barbecue today q r If we do not have a barbecue today then we will have a barbecue tomorrow p r Therefore, if it rains today then we will have a barbecue tomorrow Hypothetical Syllogism pq qr pr pq qr pr 49 p q p r it is not snowing or Jasmine is skiing p q It is snowing or Bart is playing hockey pr Therefore, Jasmine is skiing or Bart is playing hockey qr Resolution pq p r q r 50 Hypothesis: p q It is not sunny this afternoon and it is colder than yesterday r We will go swimming p only if it is sunny r s s t 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 p q rp r s s t Conclusion: t We will be home by sunset 51 1. p q Hypothesis 2. p Simplification from 1 3. r p Hypothesis 4. r Modus tollens from 2,3 5. r s Hypothesis 6. s 7. s t Modus ponens from 4,5 Hypothesis 8. t Modus ponens from 6,7 52 Chapter 1: Foundations: Logic and Proofs 53 Foundations of Logic (§1.1-1.3) Mathematical Logic is a tool for working with complicated compound statements. It includes: • A language for expressing them. • A concise notation for writing them. • A methodology for objectively reasoning about their truth or falsity. • It is the foundation for expressing formal proofs in all branches of mathematics. 54 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. 55 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. 56 The Universal Quantifier • Example: Let the u.d. of x be parking spaces at UF. Let P(x) be the predicate “x is full.” Then the universal quantification of P(x), x P(x), is the proposition: – “All parking spaces at UF are full.” – i.e., “Every parking space at UF is full.” – i.e., “For each parking space at UF, that space is full.” 57 The Existential Quantifier • Example: Let the u.d. of x be parking spaces at UF. Let P(x) be the predicate “x is full.” Then the existential quantification of P(x), x P(x), is the proposition: – “Some parking space at UF is full.” – “There is a parking space at UF that is full.” – “At least one parking space at UF is full.” 58 Review: Predicate Logic (§1.3) • Objects x, y, z, … • Predicates P, Q, R, … are functions mapping objects x to propositions P(x). • Multi-argument predicates P(x, y). • Quantifiers: [x P(x)] :≡ “For all x’s, P(x).” [x P(x)] :≡ “There is an x such that P(x).” • Universes of discourse, bound & free vars. 59 Foundations of Logic: Overview • Propositional logic (§1.1-1.2): – Basic definitions. (§1.1) – Equivalence rules & derivations. (§1.2) • Predicate logic (§1.3-1.4) – Predicates. – Quantified predicate expressions. – Equivalences & derivations. 60 Propositional Logic (§1.1) Propositional Logic is the logic of compound statements built from simpler statements using so-called Boolean connectives. Some applications in computer science: • Design of digital electronic circuits. • Expressing conditions in programs. • Queries to databases & search engines. George Boole (1815-1864) Chrysippus of Soli (ca. 281 B.C. – 205 B.C.) 61 Definition of a Proposition A proposition (p, q, r, …) is simply a statement (i.e., a declarative sentence) with a definite meaning, having a truth value that’s either true (T) or false (F) (never both, neither, or somewhere in between). (However, you might not know the actual truth value, and it might be situation-dependent.) [Later we will study probability theory, in which we assign degrees of certainty to propositions. But for now: think True/False only!] 62 Examples of Propositions • “It is raining.” (In a given situation.) • “Beijing is the capital of China.” • “1 + 2 = 3” But, the following are NOT propositions: • “Who’s there?” (interrogative, question) • “La la la la la.” (meaningless interjection) • “Just do it!” (imperative, command) • “Yeah, I sorta dunno, whatever...” (vague) • “1 + 2” (expression with a non-true/false value) 63 Operators / Connectives An operator or connective combines one or more operand expressions into a larger expression. (E.g., “+” in numeric exprs.) Unary operators take 1 operand (e.g., −3); Binary operators take 2 operands (eg 3 4). Propositional or Boolean operators operate on propositions or truth values instead of on numbers. 64 Some Popular Boolean Operators 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 ↔ 65 The Negation Operator The unary negation operator “¬” (NOT) transforms a prop. into its logical negation. E.g. If p = “I have brown hair.” then ¬p = “I do not have brown hair.” Truth table for NOT: p p T T :≡ True; F :≡ False “:≡” means “is defined as” F Operand column Result column 66 The Conjunction Operator The binary conjunction operator “” (AND) combines two propositions to form their ND logical conjunction. E.g. If p=“I will have salad for lunch.” and q=“I will have steak for dinner.”, then pq=“I will have salad for lunch and I will have steak for dinner.” Remember: “” points up like an “A”, and it means “ND” 67 Conjunction Truth Table Operand columns • Note that a p q pq conjunction F F p1 p2 … pn F T of n propositions T F will have 2n rows in its truth table. T T • Also: ¬ and operations together are sufficient to express any Boolean truth table! 68 The Disjunction Operator • The binary disjunction operator “” (OR) combines two propositions to form their logical disjunction. • p=“My car has a bad engine.” • q=“My car has a bad carburetor.” • pq=“Either my car has a bad engine, or the downwardmy car has a bad carburetor.” After pointing “axe” of “” Meaning is like “and/or” in English. splits the wood, you can take 1 piece OR the other, or both. 69 Disjunction Truth Table • Note that pq means p q pq that p is true, or q is F F true, or both are true! F T • So, this operation is T F also called inclusive or, T T because it includes the possibility that both p and q are true. • “¬” and “” together are also universal. 70 Nested Propositional Expressions • Use parentheses to group sub-expressions: “I just saw my old friend, and either he’s grown or I’ve shrunk.” = f (g s) – (f g) s would mean something different – f g s would be ambiguous • By convention, “¬” takes precedence over both “” and “”. – ¬s f means (¬s) f , not ¬ (s f) 71 A Simple Exercise Let p=“It rained last night”, q=“The sprinklers came on last night,” r=“The lawn was wet this morning.” Translate each of the following into English: ¬p = “It didn’t rain last night.” “The lawn was wet this morning, and r ¬p = it didn’t rain last night.” ¬ r p q = “Either the lawn wasn’t wet this morning, or it rained last night, or the sprinklers came on last night.” 72 The Exclusive Or Operator The binary exclusive-or operator “” (XOR) combines two propositions to form their logical “exclusive or” (exjunction?). p = “I will earn an A in this course,” q = “I will drop this course,” p q = “I will either earn an A for this course, or I will drop it (but not both!)” 73 Exclusive-Or Truth Table • Note that pq means p q pq that p is true, or q is F F true, but not both! F T • This operation is T F called exclusive or, T T because it excludes the possibility that both p and q are true. • “¬” and “” together are not universal. 74 Natural Language is Ambiguous Note that English “or” can be ambiguous regarding the “both” case! p q p "or" q “Pat is a singer or F F Pat is a writer.” - F T “Pat is a man or T F Pat is a woman.” - T T Need context to disambiguate the meaning! For this class, assume “or” means inclusive. 75 The Implication Operator antecedent consequent The implication p q states that p implies q. I.e., If p is true, then q is true; but if p is not true, then q could be either true or false. E.g., let p = “You study hard.” q = “You will get a good grade.” p q = “If you study hard, then you will get a good grade.” (else, it could go either way) 76 Examples of Implications • “If this lecture ends, then the sun will rise tomorrow.” True or False? • “If Tuesday is a day of the week, then I am a penguin.” True or False? • “If 1+1=6, then Bush is president.” True or False? • “If the moon is made of green cheese, then I am richer than Bill Gates.” True or False? 77 English Phrases Meaning p q • • • • • • • • “p implies q” “if p, then q” “if p, q” “when p, q” “whenever p, q” “p only if q” “ p is sufficient for q” “q if p” • • • • • “q when p” “q whenever p” “q is necessary for p” “q follows from p” “q is implied by p” We will see some equivalent logic expressions later. 78 The biconditional operator The biconditional p q states that p is true if and only if (IFF) q is true. p = “Bush wins the 2004 election.” q = “Bush will be president for all of 2005.” p q = “If, and only if, Bush wins the 2004 election, Bush will be president for all of 2005.” I’m still here! 2004 2005 79 Boolean Operations Summary • We have seen 1 unary operator (out of the 4 possible) and 5 binary operators (out of the 16 possible). Their truth tables are below. p F F T T q F T F T p pq pq pq pq pq T F F F T T T F T T T F F F T T F F F T T F T T 80 Some Alternative Notations Name: Propositional logic: Boolean algebra: C/C++/Java (wordwise): C/C++/Java (bitwise): not and or p pq + ! && || ~ & | xor implies != ^ iff == Logic gates: 81 End of §1.1 You have learned about: • Propositions: What they are. • Propositional logic operators’ – – – – Symbolic notations. English equivalents. Logical meaning. Truth tables. • Atomic vs. compound propositions. • Alternative notations. • Bits and bit-strings. • Next section: §1.2 – Propositional equivalences. – How to prove them. 82 Propositional Equivalence (§1.2) Two syntactically (i.e., textually) different compound propositions may be the semantically identical (i.e., have the same meaning). We call them equivalent. Learn: • Various equivalence rules or laws. • How to prove equivalences using symbolic derivations. 83 Tautologies and Contradictions A tautology is a compound proposition that is true no matter what the truth values of its atomic propositions are! Ex. p p [What is its truth table?] A contradiction is a compound proposition that is false no matter what! Ex. p p [Truth table?] Other compound props. are contingencies. 84 Predicate Logic (§1.3) • 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? 85 Applications of Predicate Logic It is the formal notation for writing perfectly clear, concise, and unambiguous mathematical definitions, axioms, and theorems (more on these in chapter 3) for any branch of mathematics. Predicate logic with function symbols, the “=” operator, and a few proof-building rules is sufficient for defining any conceivable mathematical system, and for proving anything that can be proved within that system! 86 Other Applications • Predicate logic is the foundation of the field of mathematical logic, which culminated in Gödel’s incompleteness theorem, which revealed the ultimate limits of mathematical thought: – Given any finitely describable, consistent proof procedure, there will still be some true statements that can never be proven by that procedure. Kurt Gödel 1906-1978 • I.e., we can’t discover all mathematical truths, unless we sometimes resort to making guesses. 87 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 predicatea 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). 88 Review: Propositional Logic (§1.1-1.2) • • • • • Atomic propositions: p, q, r, … Boolean operators: Compound propositions: s : (p q) r Equivalences: pq (p q) Proving equivalences using: – Truth tables. – Symbolic derivations. p q r … 89 Predicates and Quantifiers variable predicate A( x) : Computer x is under attack by an intruder B( x) : Computer x is functionin g properly Propositional functions P( x) : x 3 Q ( x, y ) : x y 3 R ( x, y , z ) : x y z 90 Predicate logic Computers {CS1, CS 2, MATH 1} A( x) : Computer x is under attack by an intruder A(CS1) T A(CS 2) F A( MATH 1) T B( x) : Computer x is functionin g properly B (CS1) F B (CS 2) T B ( MATH 1) F 91 Universal quantifier: P( x) : x 1 x x P(x) for all x it holds P (x ) (for every element in domain) x P(x) is true for every real number x Q( x ) : x 2 0 (for every element in domain) x Q(x) is not true for every real number x Counterexample: Q(0) F 92 Existential quantifier: x P (x ) there is x such that P (x ) P( x) : x 3 x P (x ) is true because P(4) T Q( x) : x 1 1 x 0 x Q (x) is not true 93 For finite domain {x1 , x2 ,, xn } x P( x) P( x1 ) P( x2 ) P( xn ) x P( x) P( x1 ) P( x2 ) P( xn ) 94 Quantifiers with restricted domain x 0 ( x 0) 2 y 0 ( y 0) 3 z 0 ( z 2 2) Precedence of operators higher lower 95 Logical equivalences with quantifiers x( P( x) Q( x)) xP( x) xQ( x) x( P( x) Q( x)) xP( x) xQ( x) x( P( x) Q( x)) xP( x) xQ( x) ? x( P( x) Q( x)) xP( x) xQ( x) ? False False 96 De Morgan’s Laws for Quantifiers xP( x) xP( x) xP( x) xP( x) 97 Example x( P( x) Q( x)) x( P( x) Q( x)) x( P( x) Q( x)) Recall that: ( p q) p q 98 Translating English into Logical Expressions P( x) x is a hummingbir d Q( x) x is large bird R( x) x lives on honey S ( x) x is richly colored “All hummingbirds are richly colored” x( P( x) S ( x)) “No large birds live on honey” x(Q( x) R( x)) “Birds that do not live on honey x(R( x) S ( x)) are dull in color” “Hummingbirds are small” x( P( x) Q( x)) 99 Universal Modus Ponens x( P( x) Q( x)) P(a), for some particular a in domain Q(a) P (x ) Q (x ) For all positive integers x , if x 4 then x 2 2 x x( P( x) Q( x)) 100 4 P(100) Therefore, 100 2 2 100 Q(100) 100