Download presentation
Presentation is loading. Please wait.
Published byMartin Andrews Modified over 8 years ago
1
CSS342: Propositions1 Professor: Munehiro Fukuda
2
CSS342: Propositions2 Introduction Propositional logic is useful in CS to analyze such behavior of code portions. Proposition: a statement that is either true or false, but not both Logic: reasoning whether a consequence of given statements is correct, but not whether each statement is true. Example: –Proposition p:All mathematicians wear sandals. (A → B) –Proposition q:Anyone who wears sandals is an algebraist (B → C) –From p and q:All mathematicians are algebraists. (A → C)
3
CSS342: Propositions3 Propositions Examples: –In math 1.The only positive integers that divide 7 are 1 and 7 itself: (true) 2.For every positive integer n, there is a prime number larger than n: (true) –In history 1.Alfred Hitchcock won an Academy Award in 1940 for directing “Rebecca”: (false, he has never won one for directing) 2.Seattle held the World’s Fair, Expo 62: (true ) –In programming languages 1.Boolean expressions in if-else, while, and for statements for ( index = 0; index < 100; index++ ) { …….; } A proposition Not a proposition
4
CSS342: Propositions4 Compound propositions Conjunction of p and q –notations: p ^ q, p && q –True only if both p and q are true –truth table Disjunction of p or q –Notations: p v q, p || q –True if either p or q or both are true –truth table pqp ^ q FFF FTF TFF TTT pqp v q FFF FTT TFT TTT
5
CSS342: Propositions5 Binary Expressions in C++ Part1 How do you examine the behavior of if-else? –if ( a > = 1 && a <= 100 ) true if 1 ≤ a ≤ 100 –if ( a >= 1 || a <= 100 ) always true a < 11 <= a <= 100100 < a a >= 1 a <= 100 false true false condition proposition a < 11 <= a <= 100100 < a a >= 1 a <= 100 false true false condition proposition
6
CSS342: Propositions6 Negation The negation of p –Notations: p, not p, ¬p !p –Truth table: Example: –P: 1 + 1 = 3 (false) –!p: !(1 + 1 = 3) ≡ 1 + 1 ≠ 3 (true) P!p FT TF
7
CSS342: Propositions7 Boolean Algebra (Axioms) When T = true and F = false: 1.If p ≠ F then p = T, If p ≠ T then p = F 2.F && F = F, T || T = T 3.T && T = T, F || F = F 4.F && T = T && F = F 5.F || T = T || F = T 6.!T = F, !F = T
8
CSS342: Propositions8 Boolean Algebra (Theorems) When T = true and F = false: p && q = q && p, p || q = q || p (p && q) && r = p && (q && r), (p || q ) || r = p || (q || r) (p || q) && (p || r) = p || q && r, p && q || p && r = p && (q || r) p && F = F, p || T = T p && T = p,p || F = p p && !p = F,p || !p = T p && p = p,p || p = p p && (p || q) = p,p || p && q = p !(!p) = p p + q && !p = p + q Commutative Law Associative Law Distributive Law Complement Law Double Negation Absorption Law Square Law Consensus Law
9
CSS342: Propositions9 Binary Expressions in C++ Part2 How do you examine the behavior of if-else statements? –Given two distance objects, d1 and 2, if ( d1 < d2 ) p: d1.feet < d2.feet q: d1.feet == d2.feet a: d1.inches < d2.inches b: d1.inches == d2.inches c: d1.inches > d2.inches false true d1 < d2d2.inchesd1.inchesd2.feet d1.feet < < < < < < = = = = = = > > > > > >
10
CSS342: Propositions10 Binary Expressions in C++ Part2 (Cont’d) bool Distance::operator < ( const Distance& d2 ) const { return ( feet < d2.feet ) || (feet == d2.feet) && (inches < d2.inches); } p: d1.feet < d2.feet q: d1.feet == d2.feet a: d1.inches < d2.inches b: d1.inches == d2.inches c: d1.inches > d2.inches p && a || p && b || p && c || q && aDistributive Law = p && (a || b || c ) || q && a!a = b || c = p && (a || !a ) || q && aComplement Law = p && T || q && aTheorem 6 = p || q && a = ( d1.feet < d2.feet ) || ( d1.feet == d2.feet ) && (d1.inches < d2.inches)
11
CSS342: Propositions11 Conditional Propositions Given two propositions such as p and q, If p then qor p → q is called a conditional proposition. –P: hypothesis, antecedent, or sufficient condition –Q: conclusion, consequent, or necessary condition if p then q ≡ p only if q: called logically equivalent. –John may take CSS342 only if he advances to CSS343. –If John takes CSS342, he advances to CSS343. q p
12
CSS342: Propositions12 Truth Table of Conditional Propositions Chair statement: if CSS gets an additional $80,000, it will hire one new faculty member. P: CSS gets an additional $80,000. Q: CSS will hire one new faculty member. If both p and q are true, the chair said a correct statement. If p is true but q is false, the chair said a wrong statement. If p is false, the chair is not responsible for his statement. We should regard it as true. pqp → q TTT TFF FTT FFT
13
CSS342: Propositions13 Two propositions: P: 1 > 2 Q: 4 < 8 According to the truth table, p → q is true, while q → p is false. C++ program: What’s the execution result? –Linux: 1 > 2 -> 4 < 8: 8 4 1 < 2: 0 –Goodall 1 > 2 -> 4 < 8: 0 4 1 < 2: 0 It depends on how result1 was initialized. In math, we consider all initialized in true. Binary Expressions in C++ Part3 void main( ) { bool result1; if ( 1 > 2 ) result1 = 4 < 8; cout 2 -> 4 < 8: " << result1 << endl; bool result2; if ( 4 < 8 ) result2 = 1 > 2; cout 1 > 2: " << result2 << endl; }
14
CSS342: Propositions14 Logical Equivalence If two different compound propositions have the same truth values no matter what truth values their constituent propositions have, they are called: –logically equivalent Example: –!(p || q) ≡ !p && !q (De Morgan’s Laws) pqp || q!(p || q)!p!q!p && !q TTTFFF F TFTFFT F FTTFTF F FFFTTT T
15
CSS342: Propositions15 De Morgan’s Laws !(p || q) ≡ !p && !q –Proved by the truth page on the previous page. !(p && q) ≡ !p || !q pqp && q!(p && q)!p!q!p || !q TTTFFF F TFFTFT T FTFTTF T FFFTTT T
16
CSS342: Propositions16 Biconditional Propositions Given two propositions such as p and q, p if and only if qp iff qor p ↔ q is called a conditional proposition. P: a necessary and sufficient condition for Q Q: a necessary and sufficient condition for P pqp ↔ q TTT TFF FTF FFT
17
CSS342: Propositions17 Biconditional Propositions Proof of the Truth Table pqp → qq → p(p → q) && (q → p)p ↔ q TTTTTT TFFTFF FTTFFF FFTTTT
18
CSS342: Propositions18 Contrapositive !q →!p –The contrapositive of p → q –Logically equivalent pqp → q!q!p!q →!p TTTFFT TFFTFF FTTFTT FFTTTT
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.