Download presentation
Presentation is loading. Please wait.
Published byElmer Parsons Modified over 9 years ago
1
1 CMSC 250 Chapter 2, Predicate Logic
2
2 CMSC 250 Definitions l Subject / predicate John / went to the store. The sky / is blue. l Propositional logic- uses statements l Predicate logic or calculus- uses predicates –predicates must be applied to a subject in order to be true or false l P(x) – means this predicate represented by P –applied to the object represented by x
3
3 CMSC 250 Quantification l x There exists an x l xFor all x's l Domain- the set where these subjects come from l ( x) [P(x)]there exists an x for which predicate p is true l ( x) [P(x)]for all x, predicate p is true l Notation: – x Z there exists an x in the integers – x R for all x's in the reals
4
4 CMSC 250 Predicate translation l A student of mine is wearing a blue shirt. –Domain: all people P –Quantification: There is at least one –Predicates: "wearing a blue shirt" and "is my student" Let B(x) represent "x is wearing a blue shirt" Let S(x) represent "x is my student" x P such that B(x) ^ S(x) l All good students are in class. –Domain: all people P –Quantification: All of them –Predicates: "are in class" and "is a good student" Let C(x) represent "x is in class" Let G(x) represent “x is a good student" x P such that G(x) C(x)
5
5 CMSC 250 Establishing truth and falsity l To show an existentially quantified statement ( ) is true, find an example. l One way to show an existentially quantified statement is false is to show it's false for every member of the domain. l To show a universally quantified statement ( ) is false, find a counterexample. l One way to show a universally quantified statement is true is to show it's true for every member of the domain.
6
6 CMSC 250 Negation of quantified statements l (there is a cat which can fly) –some cats can’t fly? –only some cats can fly? –cats can only fly sometimes? –all cats can’t fly? –watch me throw this cat out the window… l Let F(x) represent the predicate "x can fly" ~ ( x cats) [F(x)] ( x cats) [~F(x)]
7
7 CMSC 250 Negation of quantified statements l (everybody likes me) –nobody likes me? –everybody doesn’t like me? –somebody doesn’t like me? l Let L(x) represent the predicate "x likes me" ~( x people) [L(x)] ( x people) [~L(x)]
8
8 CMSC 250 Discrete Structures CMSC 250 Lecture 9 February 15, 2008
9
9 CMSC 250 Vacuous cases (for universally quantified statements) l All even prime numbers which are greater than or equal to 10 are the sum of two squares. l All students in this class who are ten feet tall have green hair. l Are these true or false? How would we show they’re true or false?
10
10 CMSC 250 Universal conditional statements and variants l A universal conditional statement: ( x D) [P(x) Q(x)] l Its contrapositive: ( x D) [~Q(x) ~P(x)] l Its converse: ( x D) [Q(x) P(x)] l Its inverse: ( x D) [~P(x) ~Q(x)] l Also applies to existentially quantified conditional statements
11
11 CMSC 250 Multiple quantification l Let C = {all chairs} and P = {all people}, and S(c,p) represent “person p is sitting in chair c " l ( p P) ( c C) [S(c,p)] l ( c C) ( p P) [S(c,p)] l ( p P) ( c C) [S(c,p)] l ( c C) ( p P) [S(c,p)]
12
12 CMSC 250 Order of mixed quantifiers l and are different! l Example- domain N- the following do not mean the same thing! l ( x) ( y) [y > x] l ( y) ( x) [y > x]
13
13 CMSC 250 Mixed multiple quantification variations l Let C = {all chairs} and P = {all people}, and S(c,p) represent “person p is sitting in chair c" l ( c C) ( p P) [S(c,p)] l ( p P) ( c C) [S(c,p)] l ( p P) ( c C) [S(c,p)] l ( c C) ( p P) [S(c,p)]
14
14 CMSC 250 Negations of multiply quantified statements l Let P= {all people}, and C= {all cats}, and L(p,c) represent “person p likes cat c" ~(( p P) ( c C) [L(p,c)]) ( p P) ( c C) [~L(p,c)]
15
15 CMSC 250 Other variations l Let S be the set of all students and C be the set of all colleges, and A(s,c) represent "student s attends college c". l Exactly one student attends college: ( s S) ( c C) [A(s,c) ~(( p S) ( u C) [p s A(p,u)])] ( s S) ( c C) [A(s,c) (( p S) ( u C) [p = s ~A(p,u)])] l At most one student attends college: ( s,p S) ( c,u C) [(A(s,c) A(p,u)) p = s] l At least two students attend college: ( s,p S) ( c,u C) [A(s,c) A(p,u) p s]
16
16 CMSC 250 Discrete Structures CMSC 250 Lecture 10 February 18, 2008
17
17 CMSC 250 Establishing truth and falsity with multiple quantification l Recall: –to show x is true, find an example. –to show x is false, find a counterexample. l Let the domain be the natural numbers
18
18 CMSC 250 Set (Euler) diagrams l Circles are used to indicate “truth sets" for a predicate –where the predicate applied to an object is true l A dot is used to indicate a specific instance l A completely contained circle indicates a "for all" relationship l An overlapping circle indicates "some" SBC P A U OR U P A All college students are brilliant. All brilliant people are scientists. All college students are scientists. Some poets are unsuccessful. Some athletes are unsuccessful. Some poets are athletes.
19
19 CMSC 250 Interpretations l Assign meanings to predicates and domains to quantified variables l One interpretation: domain N, L is < l Another interpretation: domain Q, L is < l Another interpretation: domain N, L is / (L(x, y) means "x can be divided by y evenly") l An interpretation is analogous to a row of a truth table (except there are an infinite number of them).
20
20 CMSC 250 Rules of inference for quantified statements Universal Modus Ponens ( x D) [P(x) Q(x)] a D P(a) Q(a) Universal Modus Tollens ( x D) [P(x) Q(x)] a D ~Q(a) ~P(a) Universal instantiation ( x D) [P(x)] a D P(a) Existential generalization P(a) a D ( x D) [P(x)]
21
21 CMSC 250 Rules that don't exist or need more clarification l Existential Modus Ponens doesn't exist l Existential Modus Tollens doesn't exist l Universal generalization: P(a), ( x D) [P(x)] –only if a is completely arbitrary in the domain l Existential instantiation: ( x D) [P(x)], P(a) –only if a is completely arbitrary in the domain
22
22 CMSC 250 Errors in deduction l Converse error: ( x D) [P(x) Q(x)] Q(a) P(a) l Called asserting the consequence l Inverse error: ( x D) [P(x) Q(x)] ~P(a) ~Q(a) l Called denying the hypothesis
23
23 CMSC 250 Easy formal direct proofs by deduction P1: ( x D) [P(x) Q(x)] P2: ~Q(a), where a D ( x D) [~P(x)] P1: ( x D) [P(x) Q(x)] P2: ( x D) [R(x) ~P(x)] P3: P(b), where b D Q(b) ^ ~R(b)
24
24 CMSC 250 More formal direct proofs by deduction P1: ( x D) [P(x) Q(x)] P2: ( x D) [~P(x) R(x)] P3: P(b), where b D ( x D) [Q(x) ^ R(x)] P1: ( x D) [P(x) Q(x)] P2: ( y D) [~P(y) R(y)] P3: ( z D) [~Q(z)] ( x D) [R(x)]
25
25 CMSC 250 Discrete Structures CMSC 250 Lecture 11 February 20, 2008
26
26 CMSC 250 One more proof l Note: ( x D) [A(x) ~N(x)] ( y D) [A(y) ~N(y)] ( z D) [A(z) ~N(z)] etc. l Also, the quantified variables are completely independent in different quantified predicates like ( y D) [A(y)] and ( y D) [B(y) Q(y)] P1: ( x D) [(A(x) B(x)) (M(x) N(x))] P2: ( y D) [A(y) ~N(y)] ( z D) [M(z) B(z)]
27
27 CMSC 250 Example using predicate logic l Once we define operations or concepts we can use them in defining other operations. l Consider only , , =, and the domain N l Define DIV(x,y): ( z)[x z = y] l Now we can define PRIME(y): ( x)[DIV(x,y) x = 1 x = y] l Also ODD(y): ( x)[y = 2 x + 1]
28
28 CMSC 250 Example, continued l Using these, define SUM3P(x): l Now we can state the following: ( n)( x)[x n ODD(x) SUM3P(x)]
29
29 CMSC 250 Another application- describing properties of programs l Motivation: –finding bugs –proofs of correctness –specifying programs- clarifying goals before coding A precondition is a property which must be true before some piece of code is executed, otherwise it won’t work correctly l A postcondition is a property which will be true after some piece of code executes (assuming the precondition was true beforehand) l An invariant is a property which is true at every iteration of a loop (at the top of the loop)
30
30 CMSC 250 Example i= 0; // precondition: true (meaning there are no // requirements or conditions which must be // satisfied in order for the code to work correctly) while (i < n && arr[i] < x) // invariant: 0 i < n // ( j, 0 j < i)[arr[j] < x] i++; // postcondition: n < 0 // (0 i n // ( j, 0 j < i)[arr[j] < x] // i < n arr[i] x)
31
31 CMSC 250 Discrete Structures CMSC 250 Lecture 12 February 22, 2008
32
32 CMSC 250 Another example i= 1; max= arr[0]; // precondition: true while (i < n) { // invariant: 1 i < n // ( j, 0 j < i)[arr[j] = max] // ( k, 0 k < i)[arr[k] max] if (arr[i] > max) max= arr[i]; i++; } // postcondition: n < 1 // (i = n // ( j, 0 j < n)[arr[j] = max] // ( k, 0 k < n)[arr[k] max])
33
33 CMSC 250 A further example i= 0; found= 0; // precondition: true while (i < n && !found) // invariant: found = 0 0 i < n // ( j, 0 j < i)[arr[j] x] if (arr[i] == x) found= 1; else i++; // postcondition: // n < 0 // ((found = 0 i = n // ( j, 0 j < i)[arr[j] x])) // (found = 1 0 i < n arr[i] = x // ( j, 0 j < i)[arr[j] x]]))
34
34 CMSC 250 One more example l If we need to refer to the initial value of a variable, the convention is to use its name with a prime symbol i= 0; // precondition: n 0 while (i < n – 1) { // invariant: i < n – 1 // ( j, 0 ≤ j < i)[arr[j] = arr'[j + 1]] // ( j, i ≤ j < n)[arr[j] = arr'[j]] arr[i]= arr[i + 1]; i++; } // postcondition: // n < 0 // (i = n – 1 // ( j, 0 ≤ j < i)[arr[j] = arr'[j + 1]] // [arr[n - 1] = arr'[n - 1]])
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.